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 | { |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 14 | if (!publisherPublicKeyDigest->publisherPublicKeyDigest.value || publisherPublicKeyDigest->publisherPublicKeyDigest.length == 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 | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 19 | (encoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, &publisherPublicKeyDigest->publisherPublicKeyDigest))) |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 20 | return error; |
| 21 | |
Jeff Thompson | adaf923 | 2013-08-08 14:30:29 -0700 | [diff] [blame] | 22 | return NDN_ERROR_success; |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 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 | 94ddc27 | 2013-08-08 14:17:38 -0700 | [diff] [blame] | 29 | if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 30 | (decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, 0, &publisherPublicKeyDigest->publisherPublicKeyDigest))) |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 31 | return error; |
| 32 | |
Jeff Thompson | adaf923 | 2013-08-08 14:30:29 -0700 | [diff] [blame] | 33 | return NDN_ERROR_success; |
Jeff Thompson | 8238d00 | 2013-07-10 11:56:49 -0700 | [diff] [blame] | 34 | } |
Jeff Thompson | 5633c30 | 2013-07-11 10:24:27 -0700 | [diff] [blame] | 35 | |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 36 | ndn_Error ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest |
| 37 | (struct ndn_PublisherPublicKeyDigest *publisherPublicKeyDigest, struct ndn_BinaryXmlDecoder *decoder) |
Jeff Thompson | 5633c30 | 2013-07-11 10:24:27 -0700 | [diff] [blame] | 38 | { |
| 39 | int gotExpectedTag; |
| 40 | ndn_Error error; |
Jeff Thompson | 94ddc27 | 2013-08-08 14:17:38 -0700 | [diff] [blame] | 41 | if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_PublisherPublicKeyDigest, &gotExpectedTag))) |
Jeff Thompson | 5633c30 | 2013-07-11 10:24:27 -0700 | [diff] [blame] | 42 | return error; |
| 43 | if (gotExpectedTag) { |
Jeff Thompson | 94ddc27 | 2013-08-08 14:17:38 -0700 | [diff] [blame] | 44 | if ((error = ndn_decodeBinaryXmlPublisherPublicKeyDigest(publisherPublicKeyDigest, decoder))) |
Jeff Thompson | 5633c30 | 2013-07-11 10:24:27 -0700 | [diff] [blame] | 45 | return error; |
| 46 | } |
| 47 | else { |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame] | 48 | publisherPublicKeyDigest->publisherPublicKeyDigest.value = 0; |
| 49 | publisherPublicKeyDigest->publisherPublicKeyDigest.length = 0; |
Jeff Thompson | 5633c30 | 2013-07-11 10:24:27 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Jeff Thompson | adaf923 | 2013-08-08 14:30:29 -0700 | [diff] [blame] | 52 | return NDN_ERROR_success; |
Jeff Thompson | 5633c30 | 2013-07-11 10:24:27 -0700 | [diff] [blame] | 53 | } |