blob: 493ab8c649671a03291f8f7fdd440da4fe188c3e [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
Jeff Thompsonf0fea002013-07-30 17:22:42 -070010ndn_Error ndn_encodeBinaryXmlPublisherPublicKeyDigest
11 (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlEncoder *encoder)
Jeff Thompson8238d002013-07-10 11:56:49 -070012{
13 if (!publisherPublicKeyDigest->publisherPublicKeyDigest || publisherPublicKeyDigest->publisherPublicKeyDigestLength == 0)
Jeff Thompson52331fa2013-08-06 12:41:17 -070014 return 0;
Jeff Thompson8238d002013-07-10 11:56:49 -070015
16 ndn_Error error;
Jeff Thompsonf0fea002013-07-30 17:22:42 -070017 if (error = ndn_BinaryXmlEncoder_writeBlobDTagElement
18 (encoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, publisherPublicKeyDigest->publisherPublicKeyDigest,
Jeff Thompson8238d002013-07-10 11:56:49 -070019 publisherPublicKeyDigest->publisherPublicKeyDigestLength))
20 return error;
21
22 return 0;
23}
24
Jeff Thompsonf0fea002013-07-30 17:22:42 -070025ndn_Error ndn_decodeBinaryXmlPublisherPublicKeyDigest
26 (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlDecoder *decoder)
Jeff Thompson8238d002013-07-10 11:56:49 -070027{
28 ndn_Error error;
Jeff Thompsonf0fea002013-07-30 17:22:42 -070029 if (error = ndn_BinaryXmlDecoder_readBinaryDTagElement
30 (decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, 0, &publisherPublicKeyDigest->publisherPublicKeyDigest,
Jeff Thompson8238d002013-07-10 11:56:49 -070031 &publisherPublicKeyDigest->publisherPublicKeyDigestLength))
32 return error;
33
34 return 0;
35}
Jeff Thompson5633c302013-07-11 10:24:27 -070036
Jeff Thompsonf0fea002013-07-30 17:22:42 -070037ndn_Error ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest
38 (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlDecoder *decoder)
Jeff Thompson5633c302013-07-11 10:24:27 -070039{
40 int gotExpectedTag;
41 ndn_Error error;
Jeff Thompsonf0fea002013-07-30 17:22:42 -070042 if (error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, &gotExpectedTag))
Jeff Thompson5633c302013-07-11 10:24:27 -070043 return error;
44 if (gotExpectedTag) {
Jeff Thompsonf0fea002013-07-30 17:22:42 -070045 if (error = ndn_decodeBinaryXmlPublisherPublicKeyDigest(publisherPublicKeyDigest, decoder))
Jeff Thompson5633c302013-07-11 10:24:27 -070046 return error;
47 }
48 else {
49 publisherPublicKeyDigest->publisherPublicKeyDigest = 0;
50 publisherPublicKeyDigest->publisherPublicKeyDigestLength = 0;
51 }
52
53 return 0;
54}