Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | 605671d | 2017-08-26 13:41:06 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2013-2020 Regents of the University of California. |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/signature-info.hpp" |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 23 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 25 | |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame] | 26 | #include <boost/lexical_cast.hpp> |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 29 | namespace tests { |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 30 | |
| 31 | BOOST_AUTO_TEST_SUITE(TestSignatureInfo) |
| 32 | |
| 33 | const uint8_t sigInfoRsa[] = { |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 34 | 0x16, 0x1b, // SignatureInfo |
| 35 | 0x1b, 0x01, // SignatureType |
| 36 | 0x01, // Sha256WithRsa |
| 37 | 0x1c, 0x16, // KeyLocator |
| 38 | 0x07, 0x14, // Name |
| 39 | 0x08, 0x04, |
| 40 | 0x74, 0x65, 0x73, 0x74, |
| 41 | 0x08, 0x03, |
| 42 | 0x6b, 0x65, 0x79, |
| 43 | 0x08, 0x07, |
| 44 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72 |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | BOOST_AUTO_TEST_CASE(Constructor) |
| 48 | { |
| 49 | SignatureInfo info; |
| 50 | BOOST_CHECK_EQUAL(info.getSignatureType(), -1); |
| 51 | BOOST_CHECK_EQUAL(info.hasKeyLocator(), false); |
| 52 | BOOST_CHECK_THROW(info.getKeyLocator(), SignatureInfo::Error); |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 53 | BOOST_CHECK_EQUAL(info.hasValidityPeriod(), false); |
| 54 | BOOST_CHECK_THROW(info.getValidityPeriod(), SignatureInfo::Error); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 55 | |
Davide Pesavento | 7e6f6f8 | 2017-10-31 18:05:28 -0400 | [diff] [blame] | 56 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(info), "Invalid SignatureInfo"); |
| 57 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 58 | SignatureInfo sha256Info(tlv::DigestSha256); |
| 59 | BOOST_CHECK_EQUAL(sha256Info.getSignatureType(), tlv::DigestSha256); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 60 | BOOST_CHECK_EQUAL(sha256Info.hasKeyLocator(), false); |
| 61 | BOOST_CHECK_THROW(sha256Info.getKeyLocator(), SignatureInfo::Error); |
| 62 | |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame] | 63 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(sha256Info), "DigestSha256"); |
| 64 | |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 65 | KeyLocator keyLocator("/test/key/locator"); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 66 | SignatureInfo sha256RsaInfo(tlv::SignatureSha256WithRsa, keyLocator); |
| 67 | BOOST_CHECK_EQUAL(sha256RsaInfo.getSignatureType(), tlv::SignatureSha256WithRsa); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 68 | BOOST_CHECK_EQUAL(sha256RsaInfo.hasKeyLocator(), true); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 69 | BOOST_CHECK_EQUAL(sha256RsaInfo.getKeyLocator().getName(), Name("/test/key/locator")); |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 70 | BOOST_CHECK_EQUAL(sha256RsaInfo.hasValidityPeriod(), false); |
| 71 | BOOST_CHECK_THROW(sha256RsaInfo.getValidityPeriod(), SignatureInfo::Error); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 72 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 73 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(sha256RsaInfo), |
| 74 | "SignatureSha256WithRsa Name=/test/key/locator"); |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame] | 75 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 76 | auto encoded = sha256RsaInfo.wireEncode(); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 77 | Block sigInfoBlock(sigInfoRsa, sizeof(sigInfoRsa)); |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 78 | BOOST_CHECK_EQUAL_COLLECTIONS(sigInfoBlock.wire(), sigInfoBlock.wire() + sigInfoBlock.size(), |
| 79 | encoded.wire(), encoded.wire() + encoded.size()); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 80 | |
| 81 | sha256RsaInfo = SignatureInfo(sigInfoBlock); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 82 | BOOST_CHECK_EQUAL(sha256RsaInfo.getSignatureType(), tlv::SignatureSha256WithRsa); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 83 | BOOST_CHECK_EQUAL(sha256RsaInfo.hasKeyLocator(), true); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 84 | BOOST_CHECK_EQUAL(sha256RsaInfo.getKeyLocator().getName(), Name("/test/key/locator")); |
| 85 | } |
| 86 | |
| 87 | BOOST_AUTO_TEST_CASE(ConstructorError) |
| 88 | { |
| 89 | const uint8_t error1[] = { |
| 90 | 0x15, 0x1b, // Wrong SignatureInfo (0x16, 0x1b) |
| 91 | 0x1b, 0x01, // SignatureType |
| 92 | 0x01, // Sha256WithRsa |
| 93 | 0x1c, 0x16, // KeyLocator |
| 94 | 0x07, 0x14, // Name |
| 95 | 0x08, 0x04, |
| 96 | 0x74, 0x65, 0x73, 0x74, |
| 97 | 0x08, 0x03, |
| 98 | 0x6b, 0x65, 0x79, |
| 99 | 0x08, 0x07, |
| 100 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72 |
| 101 | }; |
| 102 | Block errorBlock1(error1, sizeof(error1)); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 103 | BOOST_CHECK_THROW(SignatureInfo info(errorBlock1), tlv::Error); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 104 | |
| 105 | const uint8_t error2[] = { |
| 106 | 0x16, 0x01, // SignatureInfo |
| 107 | 0x01 // Wrong SignatureInfo value |
| 108 | }; |
| 109 | Block errorBlock2(error2, sizeof(error2)); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 110 | BOOST_CHECK_THROW(SignatureInfo info(errorBlock2), tlv::Error); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 111 | |
| 112 | const uint8_t error3[] = { |
| 113 | 0x16, 0x01, // SignatureInfo |
| 114 | 0x1a, 0x01, // Wrong SignatureType (0x1b, 0x1b) |
| 115 | 0x01, // Sha256WithRsa |
| 116 | 0x1c, 0x16, // KeyLocator |
| 117 | 0x07, 0x14, // Name |
| 118 | 0x08, 0x04, |
| 119 | 0x74, 0x65, 0x73, 0x74, |
| 120 | 0x08, 0x03, |
| 121 | 0x6b, 0x65, 0x79, |
| 122 | 0x08, 0x07, |
| 123 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72 |
| 124 | }; |
| 125 | Block errorBlock3(error3, sizeof(error3)); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 126 | BOOST_CHECK_THROW(SignatureInfo info(errorBlock3), tlv::Error); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 127 | |
| 128 | const uint8_t error4[] = { |
| 129 | 0x16, 0x00 // Empty SignatureInfo |
| 130 | }; |
| 131 | Block errorBlock4(error4, sizeof(error4)); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 132 | BOOST_CHECK_THROW(SignatureInfo info(errorBlock4), tlv::Error); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 133 | |
| 134 | } |
| 135 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 136 | BOOST_AUTO_TEST_CASE(GetSetSignatureType) |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 137 | { |
| 138 | SignatureInfo info; |
| 139 | BOOST_CHECK_EQUAL(info.getSignatureType(), -1); |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 140 | BOOST_CHECK_THROW(info.wireEncode(), SignatureInfo::Error); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 141 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 142 | info.setSignatureType(tlv::SignatureSha256WithEcdsa); |
| 143 | BOOST_CHECK_EQUAL(info.getSignatureType(), tlv::SignatureSha256WithEcdsa); |
| 144 | BOOST_CHECK_EQUAL(info.hasWire(), false); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 145 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 146 | info.wireEncode(); |
| 147 | BOOST_CHECK_EQUAL(info.hasWire(), true); |
| 148 | info.setSignatureType(tlv::SignatureSha256WithEcdsa); |
| 149 | BOOST_CHECK_EQUAL(info.hasWire(), true); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 150 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 151 | info.setSignatureType(static_cast<tlv::SignatureTypeValue>(1234)); |
| 152 | BOOST_CHECK_EQUAL(info.getSignatureType(), 1234); |
| 153 | BOOST_CHECK_EQUAL(info.hasWire(), false); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 156 | BOOST_AUTO_TEST_CASE(GetSetKeyLocator) |
| 157 | { |
| 158 | SignatureInfo info(tlv::SignatureSha256WithEcdsa); |
| 159 | BOOST_CHECK_EQUAL(info.hasKeyLocator(), false); |
| 160 | BOOST_CHECK_THROW(info.getKeyLocator(), SignatureInfo::Error); |
| 161 | |
| 162 | info.setKeyLocator(Name("/test/key/locator")); |
| 163 | BOOST_CHECK_EQUAL(info.hasKeyLocator(), true); |
| 164 | BOOST_CHECK_EQUAL(info.getKeyLocator().getName(), "/test/key/locator"); |
| 165 | BOOST_CHECK_EQUAL(info.hasWire(), false); |
| 166 | |
| 167 | info.wireEncode(); |
| 168 | BOOST_CHECK_EQUAL(info.hasWire(), true); |
| 169 | info.setKeyLocator(Name("/test/key/locator")); |
| 170 | BOOST_CHECK_EQUAL(info.hasWire(), true); |
| 171 | info.setKeyLocator(Name("/another/key/locator")); |
| 172 | BOOST_CHECK_EQUAL(info.hasWire(), false); |
| 173 | |
| 174 | info.wireEncode(); |
| 175 | BOOST_CHECK_EQUAL(info.hasWire(), true); |
| 176 | info.setKeyLocator(nullopt); |
| 177 | BOOST_CHECK_EQUAL(info.hasKeyLocator(), false); |
| 178 | BOOST_CHECK_THROW(info.getKeyLocator(), SignatureInfo::Error); |
| 179 | BOOST_CHECK_EQUAL(info.hasWire(), false); |
| 180 | } |
| 181 | |
| 182 | BOOST_AUTO_TEST_CASE(ValidityPeriod) |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 183 | { |
| 184 | const uint8_t sigInfo[] = { |
| 185 | 0x16, 0x45, // SignatureInfo |
| 186 | 0x1b, 0x01, // SignatureType |
| 187 | 0x01, // Sha256WithRsa |
| 188 | 0x1c, 0x16, // KeyLocator |
| 189 | 0x07, 0x14, // Name |
| 190 | 0x08, 0x04, |
| 191 | 0x74, 0x65, 0x73, 0x74, |
| 192 | 0x08, 0x03, |
| 193 | 0x6b, 0x65, 0x79, |
| 194 | 0x08, 0x07, |
| 195 | 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72, |
| 196 | 0xfd, 0x00, 0xfd, 0x26, // ValidityPeriod |
| 197 | 0xfd, 0x00, 0xfe, 0x0f, // NotBefore |
| 198 | 0x31, 0x39, 0x37, 0x30, 0x30, 0x31, 0x30, 0x31, // 19700101T000000 |
| 199 | 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 200 | 0xfd, 0x00, 0xff, 0x0f, // NotAfter |
| 201 | 0x31, 0x39, 0x37, 0x30, 0x30, 0x31, 0x30, 0x32, // 19700102T000000 |
| 202 | 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30 |
| 203 | }; |
| 204 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 205 | const auto notBefore = time::getUnixEpoch(); |
| 206 | const auto notAfter = notBefore + 1_day; |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 207 | security::ValidityPeriod vp1(notBefore, notAfter); |
| 208 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 209 | SignatureInfo info(tlv::SignatureSha256WithRsa, KeyLocator("/test/key/locator")); |
| 210 | BOOST_CHECK_EQUAL(info.hasValidityPeriod(), false); |
| 211 | BOOST_CHECK_THROW(info.getValidityPeriod(), SignatureInfo::Error); |
| 212 | |
| 213 | info.wireEncode(); |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 214 | info.setValidityPeriod(vp1); |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 215 | BOOST_CHECK_EQUAL(info.hasValidityPeriod(), true); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 216 | BOOST_CHECK_EQUAL(info.getValidityPeriod(), vp1); |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 217 | BOOST_CHECK_EQUAL(info.hasWire(), false); |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 218 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 219 | // encode |
| 220 | auto encoded = info.wireEncode(); |
| 221 | BOOST_CHECK_EQUAL(info.hasWire(), true); |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 222 | BOOST_CHECK_EQUAL_COLLECTIONS(sigInfo, sigInfo + sizeof(sigInfo), |
| 223 | encoded.wire(), encoded.wire() + encoded.size()); |
| 224 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 225 | info.setValidityPeriod(vp1); |
| 226 | BOOST_CHECK_EQUAL(info.hasWire(), true); |
| 227 | |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 228 | // decode |
| 229 | Block block(sigInfo, sizeof(sigInfo)); |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 230 | SignatureInfo info2(block); |
| 231 | BOOST_CHECK_EQUAL(info2.hasValidityPeriod(), true); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 232 | BOOST_CHECK_EQUAL(info2.getValidityPeriod(), vp1); |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 233 | BOOST_CHECK_EQUAL(info2.hasWire(), true); |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 234 | |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 235 | info2.setValidityPeriod(security::ValidityPeriod(notBefore, notBefore + 42_days)); |
| 236 | BOOST_CHECK_EQUAL(info2.hasValidityPeriod(), true); |
| 237 | BOOST_CHECK_NE(info2.getValidityPeriod(), vp1); |
| 238 | BOOST_CHECK(info2.getValidityPeriod().getPeriod() == std::make_pair(notBefore, notBefore + 42_days)); |
| 239 | BOOST_CHECK_EQUAL(info2.hasWire(), false); |
| 240 | |
| 241 | info2.wireEncode(); |
| 242 | BOOST_CHECK_EQUAL(info2.hasWire(), true); |
| 243 | info2.setValidityPeriod(nullopt); |
| 244 | BOOST_CHECK_EQUAL(info2.hasValidityPeriod(), false); |
| 245 | BOOST_CHECK_THROW(info2.getValidityPeriod(), SignatureInfo::Error); |
| 246 | BOOST_CHECK_EQUAL(info2.hasWire(), false); |
Yingdi Yu | 6be43f3 | 2015-06-09 14:19:54 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 249 | BOOST_AUTO_TEST_CASE(OtherTlvs) |
| 250 | { |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 251 | SignatureInfo info(tlv::SignatureSha256WithEcdsa); |
| 252 | info.appendTypeSpecificTlv("810101"_block); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 253 | BOOST_CHECK_THROW(info.getTypeSpecificTlv(0x82), SignatureInfo::Error); |
Davide Pesavento | 14c56cd | 2020-05-21 01:44:03 -0400 | [diff] [blame^] | 254 | BOOST_CHECK_EQUAL(info.getTypeSpecificTlv(0x81).type(), 0x81); |
| 255 | |
| 256 | info.wireEncode(); |
| 257 | BOOST_CHECK_EQUAL(info.hasWire(), true); |
| 258 | info.appendTypeSpecificTlv("82020202"_block); |
| 259 | BOOST_CHECK_EQUAL(info.hasWire(), false); |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame] | 262 | BOOST_AUTO_TEST_CASE(OtherTlvsEncoding) // Bug #3914 |
| 263 | { |
Junxiao Shi | 605671d | 2017-08-26 13:41:06 +0000 | [diff] [blame] | 264 | SignatureInfo info1(tlv::SignatureSha256WithRsa); |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame] | 265 | info1.appendTypeSpecificTlv(makeStringBlock(101, "First")); |
| 266 | info1.appendTypeSpecificTlv(makeStringBlock(102, "Second")); |
| 267 | info1.appendTypeSpecificTlv(makeStringBlock(103, "Third")); |
| 268 | |
Junxiao Shi | 605671d | 2017-08-26 13:41:06 +0000 | [diff] [blame] | 269 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(info1), "SignatureSha256WithRsa { 101 102 103 }"); |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame] | 270 | |
| 271 | SignatureInfo info2; |
| 272 | info2.wireDecode(info1.wireEncode()); |
| 273 | BOOST_CHECK_EQUAL(info1, info2); |
| 274 | |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame] | 275 | const uint8_t infoBytes[] = { |
Junxiao Shi | 605671d | 2017-08-26 13:41:06 +0000 | [diff] [blame] | 276 | 0x16, 0x19, // SignatureInfo |
| 277 | 0x1b, 0x01, 0x01, // SignatureType=1 |
| 278 | 0x65, 0x05, 0x46, 0x69, 0x72, 0x73, 0x74, // 101 "First" |
| 279 | 0x66, 0x06, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, // 102 "Second" |
| 280 | 0x67, 0x05, 0x54, 0x68, 0x69, 0x72, 0x64 // 103 "Third" |
Alexander Afanasyev | 4146975 | 2017-01-10 21:51:55 -0800 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | SignatureInfo info3(Block(infoBytes, sizeof(infoBytes))); |
| 284 | BOOST_CHECK_EQUAL(info3, info1); |
| 285 | BOOST_CHECK_EQUAL_COLLECTIONS(infoBytes, infoBytes + sizeof(infoBytes), |
| 286 | info1.wireEncode().begin(), info1.wireEncode().end()); |
| 287 | } |
| 288 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 289 | BOOST_AUTO_TEST_SUITE_END() // TestSignatureInfo |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 290 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 291 | } // namespace tests |
Yingdi Yu | 4a55705 | 2014-07-09 16:40:37 -0700 | [diff] [blame] | 292 | } // namespace ndn |