blob: bce4a7906b3c6ccc3531723a8d71e402b25b883e [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
Jeff Thompson53412192013-08-06 13:35:50 -07007#include "binary-xml.h"
8#include "binary-xml-publisher-public-key-digest.h"
Jeff Thompson8238d002013-07-10 11:56:49 -07009
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 Thompsonadaf9232013-08-08 14:30:29 -070014 return NDN_ERROR_success;
Jeff Thompson8238d002013-07-10 11:56:49 -070015
16 ndn_Error error;
Jeff Thompson94ddc272013-08-08 14:17:38 -070017 if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
Jeff Thompsonf0fea002013-07-30 17:22:42 -070018 (encoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, publisherPublicKeyDigest->publisherPublicKeyDigest,
Jeff Thompson94ddc272013-08-08 14:17:38 -070019 publisherPublicKeyDigest->publisherPublicKeyDigestLength)))
Jeff Thompson8238d002013-07-10 11:56:49 -070020 return error;
21
Jeff Thompsonadaf9232013-08-08 14:30:29 -070022 return NDN_ERROR_success;
Jeff Thompson8238d002013-07-10 11:56:49 -070023}
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 Thompson94ddc272013-08-08 14:17:38 -070029 if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
Jeff Thompsonf0fea002013-07-30 17:22:42 -070030 (decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, 0, &publisherPublicKeyDigest->publisherPublicKeyDigest,
Jeff Thompson94ddc272013-08-08 14:17:38 -070031 &publisherPublicKeyDigest->publisherPublicKeyDigestLength)))
Jeff Thompson8238d002013-07-10 11:56:49 -070032 return error;
33
Jeff Thompsonadaf9232013-08-08 14:30:29 -070034 return NDN_ERROR_success;
Jeff Thompson8238d002013-07-10 11:56:49 -070035}
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 Thompson94ddc272013-08-08 14:17:38 -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 Thompson94ddc272013-08-08 14:17:38 -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
Jeff Thompsonadaf9232013-08-08 14:30:29 -070053 return NDN_ERROR_success;
Jeff Thompson5633c302013-07-11 10:24:27 -070054}