Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * Derived from PublisherPublicKeyDigest.js by Meki Cheraoui. |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame^] | 7 | #include "binary-xml.h" |
| 8 | #include "binary-xml-publisher-public-key-digest.h" |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 9 | |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 10 | ndn_Error ndn_encodeBinaryXmlPublisherPublicKeyDigest |
| 11 | (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlEncoder *encoder) |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 12 | { |
| 13 | if (!publisherPublicKeyDigest->publisherPublicKeyDigest || publisherPublicKeyDigest->publisherPublicKeyDigestLength == 0) |
Jeff Thompson | 52331fa | 2013-08-06 12:41:17 -0700 | [diff] [blame] | 14 | return 0; |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 15 | |
| 16 | ndn_Error error; |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 17 | if (error = ndn_BinaryXmlEncoder_writeBlobDTagElement |
| 18 | (encoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, publisherPublicKeyDigest->publisherPublicKeyDigest, |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 19 | publisherPublicKeyDigest->publisherPublicKeyDigestLength)) |
| 20 | return error; |
| 21 | |
| 22 | return 0; |
| 23 | } |
| 24 | |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 25 | ndn_Error ndn_decodeBinaryXmlPublisherPublicKeyDigest |
| 26 | (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlDecoder *decoder) |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 27 | { |
| 28 | ndn_Error error; |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 29 | if (error = ndn_BinaryXmlDecoder_readBinaryDTagElement |
| 30 | (decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, 0, &publisherPublicKeyDigest->publisherPublicKeyDigest, |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 31 | &publisherPublicKeyDigest->publisherPublicKeyDigestLength)) |
| 32 | return error; |
| 33 | |
| 34 | return 0; |
| 35 | } |
Jeff Thompson | 5633c30 | 2013-07-11 10:24:27 -0700 | [diff] [blame] | 36 | |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 37 | ndn_Error ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest |
| 38 | (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlDecoder *decoder) |
Jeff Thompson | 5633c30 | 2013-07-11 10:24:27 -0700 | [diff] [blame] | 39 | { |
| 40 | int gotExpectedTag; |
| 41 | ndn_Error error; |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 42 | if (error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, &gotExpectedTag)) |
Jeff Thompson | 5633c30 | 2013-07-11 10:24:27 -0700 | [diff] [blame] | 43 | return error; |
| 44 | if (gotExpectedTag) { |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 45 | if (error = ndn_decodeBinaryXmlPublisherPublicKeyDigest(publisherPublicKeyDigest, decoder)) |
Jeff Thompson | 5633c30 | 2013-07-11 10:24:27 -0700 | [diff] [blame] | 46 | return error; |
| 47 | } |
| 48 | else { |
| 49 | publisherPublicKeyDigest->publisherPublicKeyDigest = 0; |
| 50 | publisherPublicKeyDigest->publisherPublicKeyDigestLength = 0; |
| 51 | } |
| 52 | |
| 53 | return 0; |
| 54 | } |