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