blob: 4748147a092a624c2b3c94fb281834d8538375df [file] [log] [blame]
Jeff Thompson8238d002013-07-10 11:56:49 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson8238d002013-07-10 11:56:49 -07004 * Derived from PublisherPublicKeyDigest.js by Meki Cheraoui.
5 * See COPYING for copyright and distribution information.
6 */
7
Jeff Thompson53412192013-08-06 13:35:50 -07008#include "binary-xml.h"
9#include "binary-xml-publisher-public-key-digest.h"
Jeff Thompson8238d002013-07-10 11:56:49 -070010
Jeff Thompsonf0fea002013-07-30 17:22:42 -070011ndn_Error ndn_encodeBinaryXmlPublisherPublicKeyDigest
12 (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlEncoder *encoder)
Jeff Thompson8238d002013-07-10 11:56:49 -070013{
Jeff Thompson93034532013-10-08 11:52:43 -070014 if (!publisherPublicKeyDigest->publisherPublicKeyDigest.value || publisherPublicKeyDigest->publisherPublicKeyDigest.length == 0)
Jeff Thompsonadaf9232013-08-08 14:30:29 -070015 return NDN_ERROR_success;
Jeff Thompson8238d002013-07-10 11:56:49 -070016
17 ndn_Error error;
Jeff Thompson94ddc272013-08-08 14:17:38 -070018 if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement
Jeff Thompson93034532013-10-08 11:52:43 -070019 (encoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, &publisherPublicKeyDigest->publisherPublicKeyDigest)))
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 Thompson93034532013-10-08 11:52:43 -070030 (decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, 0, &publisherPublicKeyDigest->publisherPublicKeyDigest)))
Jeff Thompson8238d002013-07-10 11:56:49 -070031 return error;
32
Jeff Thompsonadaf9232013-08-08 14:30:29 -070033 return NDN_ERROR_success;
Jeff Thompson8238d002013-07-10 11:56:49 -070034}
Jeff Thompson5633c302013-07-11 10:24:27 -070035
Jeff Thompsonf0fea002013-07-30 17:22:42 -070036ndn_Error ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest
37 (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlDecoder *decoder)
Jeff Thompson5633c302013-07-11 10:24:27 -070038{
39 int gotExpectedTag;
40 ndn_Error error;
Jeff Thompson94ddc272013-08-08 14:17:38 -070041 if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, &gotExpectedTag)))
Jeff Thompson5633c302013-07-11 10:24:27 -070042 return error;
43 if (gotExpectedTag) {
Jeff Thompson94ddc272013-08-08 14:17:38 -070044 if ((error = ndn_decodeBinaryXmlPublisherPublicKeyDigest(publisherPublicKeyDigest, decoder)))
Jeff Thompson5633c302013-07-11 10:24:27 -070045 return error;
46 }
47 else {
Jeff Thompson93034532013-10-08 11:52:43 -070048 publisherPublicKeyDigest->publisherPublicKeyDigest.value = 0;
49 publisherPublicKeyDigest->publisherPublicKeyDigest.length = 0;
Jeff Thompson5633c302013-07-11 10:24:27 -070050 }
51
Jeff Thompsonadaf9232013-08-08 14:30:29 -070052 return NDN_ERROR_success;
Jeff Thompson5633c302013-07-11 10:24:27 -070053}