blob: 00e35824eb0b574d4d087f5e2b029c53c7fe86bb [file] [log] [blame]
Jeff Thompson8238d002013-07-10 11:56:49 -07001/**
2 * @author: Jeff Thompson
3 * Derived from PublisherPublicKeyDigest.js by Meki Cheraoui.
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "BinaryXML.h"
8#include "BinaryXMLPublisherPublicKeyDigest.h"
9
10ndn_Error ndn_encodeBinaryXMLPublisherPublicKeyDigest
11 (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXMLEncoder *encoder)
12{
13 if (!publisherPublicKeyDigest->publisherPublicKeyDigest || publisherPublicKeyDigest->publisherPublicKeyDigestLength == 0)
14 return;
15
16 ndn_Error error;
17 if (error = ndn_BinaryXMLEncoder_writeBlobDTagElement
18 (encoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, publisherPublicKeyDigest->publisherPublicKeyDigest,
19 publisherPublicKeyDigest->publisherPublicKeyDigestLength))
20 return error;
21
22 return 0;
23}
24
25ndn_Error ndn_decodeBinaryXMLPublisherPublicKeyDigest
26 (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXMLDecoder *decoder)
27{
28 ndn_Error error;
29 if (error = ndn_BinaryXMLDecoder_readBinaryDTagElement
30 (decoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, 0, &publisherPublicKeyDigest->publisherPublicKeyDigest,
31 &publisherPublicKeyDigest->publisherPublicKeyDigestLength))
32 return error;
33
34 return 0;
35}
Jeff Thompson5633c302013-07-11 10:24:27 -070036
37ndn_Error ndn_decodeOptionalBinaryXMLPublisherPublicKeyDigest
38 (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXMLDecoder *decoder)
39{
40 int gotExpectedTag;
41 ndn_Error error;
42 if (error = ndn_BinaryXMLDecoder_peekDTag(decoder, ndn_BinaryXML_DTag_PublisherPublicKeyDigest, &gotExpectedTag))
43 return error;
44 if (gotExpectedTag) {
45 if (error = ndn_decodeBinaryXMLPublisherPublicKeyDigest(publisherPublicKeyDigest, decoder))
46 return error;
47 }
48 else {
49 publisherPublicKeyDigest->publisherPublicKeyDigest = 0;
50 publisherPublicKeyDigest->publisherPublicKeyDigestLength = 0;
51 }
52
53 return 0;
54}