blob: 37015bc2e679d8ead2e5c579a8cefadc162e03c8 [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{
14 if (!publisherPublicKeyDigest->publisherPublicKeyDigest || publisherPublicKeyDigest->publisherPublicKeyDigestLength == 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 Thompsonf0fea002013-07-30 17:22:42 -070019 (encoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, publisherPublicKeyDigest->publisherPublicKeyDigest,
Jeff Thompson94ddc272013-08-08 14:17:38 -070020 publisherPublicKeyDigest->publisherPublicKeyDigestLength)))
Jeff Thompson8238d002013-07-10 11:56:49 -070021 return error;
22
Jeff Thompsonadaf9232013-08-08 14:30:29 -070023 return NDN_ERROR_success;
Jeff Thompson8238d002013-07-10 11:56:49 -070024}
25
Jeff Thompsonf0fea002013-07-30 17:22:42 -070026ndn_Error ndn_decodeBinaryXmlPublisherPublicKeyDigest
27 (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlDecoder *decoder)
Jeff Thompson8238d002013-07-10 11:56:49 -070028{
29 ndn_Error error;
Jeff Thompson94ddc272013-08-08 14:17:38 -070030 if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement
Jeff Thompsonf0fea002013-07-30 17:22:42 -070031 (decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, 0, &publisherPublicKeyDigest->publisherPublicKeyDigest,
Jeff Thompson94ddc272013-08-08 14:17:38 -070032 &publisherPublicKeyDigest->publisherPublicKeyDigestLength)))
Jeff Thompson8238d002013-07-10 11:56:49 -070033 return error;
34
Jeff Thompsonadaf9232013-08-08 14:30:29 -070035 return NDN_ERROR_success;
Jeff Thompson8238d002013-07-10 11:56:49 -070036}
Jeff Thompson5633c302013-07-11 10:24:27 -070037
Jeff Thompsonf0fea002013-07-30 17:22:42 -070038ndn_Error ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest
39 (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlDecoder *decoder)
Jeff Thompson5633c302013-07-11 10:24:27 -070040{
41 int gotExpectedTag;
42 ndn_Error error;
Jeff Thompson94ddc272013-08-08 14:17:38 -070043 if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, &gotExpectedTag)))
Jeff Thompson5633c302013-07-11 10:24:27 -070044 return error;
45 if (gotExpectedTag) {
Jeff Thompson94ddc272013-08-08 14:17:38 -070046 if ((error = ndn_decodeBinaryXmlPublisherPublicKeyDigest(publisherPublicKeyDigest, decoder)))
Jeff Thompson5633c302013-07-11 10:24:27 -070047 return error;
48 }
49 else {
50 publisherPublicKeyDigest->publisherPublicKeyDigest = 0;
51 publisherPublicKeyDigest->publisherPublicKeyDigestLength = 0;
52 }
53
Jeff Thompsonadaf9232013-08-08 14:30:29 -070054 return NDN_ERROR_success;
Jeff Thompson5633c302013-07-11 10:24:27 -070055}