Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 7e6f6f8 | 2017-10-31 18:05:28 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2023 Regents of the University of California. |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -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/security/signing-info.hpp" |
Spencer Lee | 308bc44 | 2015-11-24 02:59:55 -0700 | [diff] [blame] | 23 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 25 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 26 | #include <boost/lexical_cast.hpp> |
| 27 | #include <sstream> |
| 28 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 29 | namespace ndn::tests { |
| 30 | |
| 31 | using namespace ndn::security; |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 32 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 33 | BOOST_AUTO_TEST_SUITE(Security) |
| 34 | BOOST_AUTO_TEST_SUITE(TestSigningInfo) |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 35 | |
| 36 | BOOST_AUTO_TEST_CASE(Basic) |
| 37 | { |
Spencer Lee | 308bc44 | 2015-11-24 02:59:55 -0700 | [diff] [blame] | 38 | Name id("/my-identity"); |
| 39 | Name key("/my-key"); |
| 40 | Name cert("/my-cert"); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 41 | |
| 42 | SigningInfo info; |
| 43 | |
| 44 | BOOST_CHECK_EQUAL(info.getSignerType(), SigningInfo::SIGNER_TYPE_NULL); |
Eric Newberry | 78ffc63 | 2020-05-17 15:13:46 -0700 | [diff] [blame] | 45 | BOOST_CHECK_EQUAL(info.getSignerName(), Name()); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 46 | BOOST_CHECK_EQUAL(info.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Eric Newberry | b74bbda | 2020-06-18 19:33:58 -0700 | [diff] [blame] | 47 | BOOST_CHECK_EQUAL(info.getSignedInterestFormat(), SignedInterestFormat::V02); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 48 | |
| 49 | const SignatureInfo& sigInfo = info.getSignatureInfo(); |
| 50 | BOOST_CHECK_EQUAL(sigInfo.getSignatureType(), -1); |
| 51 | BOOST_CHECK_EQUAL(sigInfo.hasKeyLocator(), false); |
| 52 | |
| 53 | info.setSigningIdentity(id); |
| 54 | BOOST_CHECK_EQUAL(info.getSignerType(), SigningInfo::SIGNER_TYPE_ID); |
| 55 | BOOST_CHECK_EQUAL(info.getSignerName(), id); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 56 | BOOST_CHECK_EQUAL(info.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Eric Newberry | b74bbda | 2020-06-18 19:33:58 -0700 | [diff] [blame] | 57 | BOOST_CHECK_EQUAL(info.getSignedInterestFormat(), SignedInterestFormat::V02); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 58 | |
| 59 | SigningInfo infoId(SigningInfo::SIGNER_TYPE_ID, id); |
| 60 | BOOST_CHECK_EQUAL(infoId.getSignerType(), SigningInfo::SIGNER_TYPE_ID); |
| 61 | BOOST_CHECK_EQUAL(infoId.getSignerName(), id); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 62 | BOOST_CHECK_EQUAL(infoId.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Eric Newberry | b74bbda | 2020-06-18 19:33:58 -0700 | [diff] [blame] | 63 | BOOST_CHECK_EQUAL(infoId.getSignedInterestFormat(), SignedInterestFormat::V02); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 64 | |
| 65 | info.setSigningKeyName(key); |
| 66 | BOOST_CHECK_EQUAL(info.getSignerType(), SigningInfo::SIGNER_TYPE_KEY); |
| 67 | BOOST_CHECK_EQUAL(info.getSignerName(), key); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 68 | BOOST_CHECK_EQUAL(info.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Eric Newberry | b74bbda | 2020-06-18 19:33:58 -0700 | [diff] [blame] | 69 | BOOST_CHECK_EQUAL(info.getSignedInterestFormat(), SignedInterestFormat::V02); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 70 | |
| 71 | SigningInfo infoKey(SigningInfo::SIGNER_TYPE_KEY, key); |
| 72 | BOOST_CHECK_EQUAL(infoKey.getSignerType(), SigningInfo::SIGNER_TYPE_KEY); |
| 73 | BOOST_CHECK_EQUAL(infoKey.getSignerName(), key); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 74 | BOOST_CHECK_EQUAL(infoKey.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Eric Newberry | b74bbda | 2020-06-18 19:33:58 -0700 | [diff] [blame] | 75 | BOOST_CHECK_EQUAL(infoKey.getSignedInterestFormat(), SignedInterestFormat::V02); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 76 | |
| 77 | info.setSigningCertName(cert); |
| 78 | BOOST_CHECK_EQUAL(info.getSignerType(), SigningInfo::SIGNER_TYPE_CERT); |
| 79 | BOOST_CHECK_EQUAL(info.getSignerName(), cert); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 80 | BOOST_CHECK_EQUAL(info.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Eric Newberry | b74bbda | 2020-06-18 19:33:58 -0700 | [diff] [blame] | 81 | BOOST_CHECK_EQUAL(info.getSignedInterestFormat(), SignedInterestFormat::V02); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 82 | |
| 83 | SigningInfo infoCert(SigningInfo::SIGNER_TYPE_CERT, cert); |
| 84 | BOOST_CHECK_EQUAL(infoCert.getSignerType(), SigningInfo::SIGNER_TYPE_CERT); |
| 85 | BOOST_CHECK_EQUAL(infoCert.getSignerName(), cert); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 86 | BOOST_CHECK_EQUAL(infoCert.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Eric Newberry | b74bbda | 2020-06-18 19:33:58 -0700 | [diff] [blame] | 87 | BOOST_CHECK_EQUAL(infoCert.getSignedInterestFormat(), SignedInterestFormat::V02); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 88 | |
| 89 | info.setSha256Signing(); |
| 90 | BOOST_CHECK_EQUAL(info.getSignerType(), SigningInfo::SIGNER_TYPE_SHA256); |
Eric Newberry | 78ffc63 | 2020-05-17 15:13:46 -0700 | [diff] [blame] | 91 | BOOST_CHECK_EQUAL(info.getSignerName(), Name()); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 92 | BOOST_CHECK_EQUAL(info.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Eric Newberry | b74bbda | 2020-06-18 19:33:58 -0700 | [diff] [blame] | 93 | BOOST_CHECK_EQUAL(info.getSignedInterestFormat(), SignedInterestFormat::V02); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 94 | |
| 95 | SigningInfo infoSha(SigningInfo::SIGNER_TYPE_SHA256); |
| 96 | BOOST_CHECK_EQUAL(infoSha.getSignerType(), SigningInfo::SIGNER_TYPE_SHA256); |
Eric Newberry | 78ffc63 | 2020-05-17 15:13:46 -0700 | [diff] [blame] | 97 | BOOST_CHECK_EQUAL(infoSha.getSignerName(), Name()); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 98 | BOOST_CHECK_EQUAL(infoSha.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Eric Newberry | b74bbda | 2020-06-18 19:33:58 -0700 | [diff] [blame] | 99 | BOOST_CHECK_EQUAL(infoSha.getSignedInterestFormat(), SignedInterestFormat::V02); |
laqinfan | 56a812d | 2019-06-03 15:33:58 -0500 | [diff] [blame] | 100 | |
| 101 | std::string encodedKey("QjM3NEEyNkE3MTQ5MDQzN0FBMDI0RTRGQURENUI0OTdGRE" |
| 102 | "ZGMUE4RUE2RkYxMkY2RkI2NUFGMjcyMEI1OUNDRg=="); |
| 103 | info.setSigningHmacKey(encodedKey); |
| 104 | BOOST_CHECK_EQUAL(info.getSignerType(), SigningInfo::SIGNER_TYPE_HMAC); |
| 105 | BOOST_CHECK_EQUAL(info.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Eric Newberry | b74bbda | 2020-06-18 19:33:58 -0700 | [diff] [blame] | 106 | BOOST_CHECK_EQUAL(info.getSignedInterestFormat(), SignedInterestFormat::V02); |
laqinfan | 56a812d | 2019-06-03 15:33:58 -0500 | [diff] [blame] | 107 | |
| 108 | SigningInfo infoHmac(SigningInfo::SIGNER_TYPE_HMAC, info.getSignerName()); |
| 109 | BOOST_CHECK_EQUAL(infoHmac.getSignerType(), SigningInfo::SIGNER_TYPE_HMAC); |
| 110 | BOOST_CHECK_EQUAL(infoHmac.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Eric Newberry | b74bbda | 2020-06-18 19:33:58 -0700 | [diff] [blame] | 111 | BOOST_CHECK_EQUAL(infoHmac.getSignedInterestFormat(), SignedInterestFormat::V02); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | BOOST_AUTO_TEST_CASE(CustomSignatureInfo) |
| 115 | { |
| 116 | SigningInfo info1; |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 117 | BOOST_CHECK_EQUAL(info1.getSignatureInfo(), SignatureInfo()); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 118 | |
| 119 | SignatureInfo si; |
| 120 | si.setKeyLocator(Name("ndn:/test/key/locator")); |
| 121 | info1.setSignatureInfo(si); |
| 122 | |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 123 | BOOST_CHECK_EQUAL(info1.getSignatureInfo(), si); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 124 | |
Eric Newberry | 78ffc63 | 2020-05-17 15:13:46 -0700 | [diff] [blame] | 125 | SigningInfo info2(SigningInfo::SIGNER_TYPE_NULL, Name(), si); |
Junxiao Shi | 72c0c64 | 2018-04-20 15:41:09 +0000 | [diff] [blame] | 126 | BOOST_CHECK_EQUAL(info2.getSignatureInfo(), si); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Spencer Lee | 308bc44 | 2015-11-24 02:59:55 -0700 | [diff] [blame] | 129 | BOOST_AUTO_TEST_CASE(FromString) |
| 130 | { |
| 131 | SigningInfo infoDefault(""); |
| 132 | BOOST_CHECK_EQUAL(infoDefault.getSignerType(), SigningInfo::SIGNER_TYPE_NULL); |
Eric Newberry | 78ffc63 | 2020-05-17 15:13:46 -0700 | [diff] [blame] | 133 | BOOST_CHECK_EQUAL(infoDefault.getSignerName(), Name()); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 134 | BOOST_CHECK_EQUAL(infoDefault.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Spencer Lee | 308bc44 | 2015-11-24 02:59:55 -0700 | [diff] [blame] | 135 | |
| 136 | SigningInfo infoId("id:/my-identity"); |
| 137 | BOOST_CHECK_EQUAL(infoId.getSignerType(), SigningInfo::SIGNER_TYPE_ID); |
| 138 | BOOST_CHECK_EQUAL(infoId.getSignerName(), "/my-identity"); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 139 | BOOST_CHECK_EQUAL(infoId.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Spencer Lee | 308bc44 | 2015-11-24 02:59:55 -0700 | [diff] [blame] | 140 | |
| 141 | SigningInfo infoKey("key:/my-key"); |
| 142 | BOOST_CHECK_EQUAL(infoKey.getSignerType(), SigningInfo::SIGNER_TYPE_KEY); |
| 143 | BOOST_CHECK_EQUAL(infoKey.getSignerName(), "/my-key"); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 144 | BOOST_CHECK_EQUAL(infoKey.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Spencer Lee | 308bc44 | 2015-11-24 02:59:55 -0700 | [diff] [blame] | 145 | |
| 146 | SigningInfo infoCert("cert:/my-cert"); |
| 147 | BOOST_CHECK_EQUAL(infoCert.getSignerType(), SigningInfo::SIGNER_TYPE_CERT); |
| 148 | BOOST_CHECK_EQUAL(infoCert.getSignerName(), "/my-cert"); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 149 | BOOST_CHECK_EQUAL(infoCert.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Spencer Lee | 308bc44 | 2015-11-24 02:59:55 -0700 | [diff] [blame] | 150 | |
laqinfan | 56a812d | 2019-06-03 15:33:58 -0500 | [diff] [blame] | 151 | SigningInfo infoHmac("hmac-sha256:QjM3NEEyNkE3MTQ5MDQzN0FBMDI0RTRGQURENU" |
| 152 | "I0OTdGREZGMUE4RUE2RkYxMkY2RkI2NUFGMjcyMEI1OUNDRg=="); |
| 153 | BOOST_CHECK_EQUAL(infoHmac.getSignerType(), SigningInfo::SIGNER_TYPE_HMAC); |
| 154 | BOOST_CHECK_EQUAL(infoHmac.getSignerName().getPrefix(3), SigningInfo::getHmacIdentity()); |
| 155 | BOOST_CHECK_EQUAL(infoHmac.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
| 156 | |
Spencer Lee | 308bc44 | 2015-11-24 02:59:55 -0700 | [diff] [blame] | 157 | SigningInfo infoSha("id:/localhost/identity/digest-sha256"); |
| 158 | BOOST_CHECK_EQUAL(infoSha.getSignerType(), SigningInfo::SIGNER_TYPE_SHA256); |
Eric Newberry | 78ffc63 | 2020-05-17 15:13:46 -0700 | [diff] [blame] | 159 | BOOST_CHECK_EQUAL(infoSha.getSignerName(), Name()); |
Yingdi Yu | 99b2a00 | 2015-08-12 12:47:44 -0700 | [diff] [blame] | 160 | BOOST_CHECK_EQUAL(infoSha.getDigestAlgorithm(), DigestAlgorithm::SHA256); |
Spencer Lee | 308bc44 | 2015-11-24 02:59:55 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | BOOST_AUTO_TEST_CASE(ToString) |
| 164 | { |
| 165 | // We can't use lexical_cast due to Boost Bug 6298. |
| 166 | std::stringstream ss; |
| 167 | ss << SigningInfo(); |
| 168 | BOOST_CHECK_EQUAL(ss.str(), ""); |
| 169 | |
| 170 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>( |
| 171 | SigningInfo(SigningInfo::SIGNER_TYPE_ID, "/my-identity")), "id:/my-identity"); |
| 172 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>( |
| 173 | SigningInfo(SigningInfo::SIGNER_TYPE_KEY, "/my-key")), "key:/my-key"); |
| 174 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>( |
| 175 | SigningInfo(SigningInfo::SIGNER_TYPE_CERT, "/my-cert")), "cert:/my-cert"); |
| 176 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>( |
| 177 | SigningInfo(SigningInfo::SIGNER_TYPE_SHA256)), |
| 178 | "id:/localhost/identity/digest-sha256"); |
laqinfan | 56a812d | 2019-06-03 15:33:58 -0500 | [diff] [blame] | 179 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>( |
| 180 | SigningInfo(SigningInfo::SIGNER_TYPE_HMAC, "/localhost/identity/hmac/1234")), |
| 181 | "id:/localhost/identity/hmac/1234"); |
Spencer Lee | 308bc44 | 2015-11-24 02:59:55 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Alexander Afanasyev | c95f564 | 2017-01-04 17:34:26 -0800 | [diff] [blame] | 184 | BOOST_AUTO_TEST_CASE(Chaining) |
| 185 | { |
| 186 | SigningInfo info = SigningInfo() |
| 187 | .setSigningIdentity("/identity") |
| 188 | .setSigningKeyName("/key/name") |
| 189 | .setSigningCertName("/cert/name") |
Alexander Afanasyev | d6d78aa | 2017-01-02 18:14:23 -0800 | [diff] [blame] | 190 | .setPibIdentity(Identity()) |
| 191 | .setPibKey(Key()) |
Alexander Afanasyev | c95f564 | 2017-01-04 17:34:26 -0800 | [diff] [blame] | 192 | .setSha256Signing() |
| 193 | .setDigestAlgorithm(DigestAlgorithm::SHA256) |
| 194 | .setSignatureInfo(SignatureInfo()); |
| 195 | |
| 196 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(info), "id:/localhost/identity/digest-sha256"); |
| 197 | } |
| 198 | |
Nick Gordon | 2a6d45a | 2017-01-25 14:10:44 -0600 | [diff] [blame] | 199 | BOOST_AUTO_TEST_CASE(OperatorEquals) |
| 200 | { |
| 201 | // Check name equality |
| 202 | SigningInfo info1("id:/my-id"); |
| 203 | SigningInfo info2("id:/my-id"); |
| 204 | BOOST_CHECK_EQUAL(info1, info2); |
| 205 | // Change name, check inequality |
| 206 | info2 = SigningInfo("id:/not-same-id"); |
| 207 | BOOST_CHECK_NE(info1, info2); |
| 208 | |
| 209 | // Check name, digest algo equality |
| 210 | info1 = SigningInfo("id:/my-id"); |
| 211 | info2 = SigningInfo("id:/my-id"); |
| 212 | info1.setDigestAlgorithm(DigestAlgorithm::SHA256); |
| 213 | info2.setDigestAlgorithm(DigestAlgorithm::SHA256); |
| 214 | BOOST_CHECK_EQUAL(info1, info2); |
| 215 | // Change digest algo, check inequality |
| 216 | info2.setDigestAlgorithm(DigestAlgorithm::NONE); |
| 217 | BOOST_CHECK_NE(info1, info2); |
| 218 | |
| 219 | // Check name, digest algo, signature info equality |
| 220 | info1 = SigningInfo("id:/my-id"); |
| 221 | info2 = SigningInfo("id:/my-id"); |
| 222 | info1.setDigestAlgorithm(DigestAlgorithm::SHA256); |
| 223 | info2.setDigestAlgorithm(DigestAlgorithm::SHA256); |
Davide Pesavento | 7e6f6f8 | 2017-10-31 18:05:28 -0400 | [diff] [blame] | 224 | SignatureInfo sigInfo1(tlv::DigestSha256); |
Nick Gordon | 2a6d45a | 2017-01-25 14:10:44 -0600 | [diff] [blame] | 225 | info1.setSignatureInfo(sigInfo1); |
| 226 | info2.setSignatureInfo(sigInfo1); |
| 227 | BOOST_CHECK_EQUAL(info1, info2); |
| 228 | // Change signature info, check inequality |
Davide Pesavento | 7e6f6f8 | 2017-10-31 18:05:28 -0400 | [diff] [blame] | 229 | SignatureInfo sigInfo2(tlv::SignatureSha256WithRsa); |
Nick Gordon | 2a6d45a | 2017-01-25 14:10:44 -0600 | [diff] [blame] | 230 | info2.setSignatureInfo(sigInfo2); |
| 231 | BOOST_CHECK_NE(info1, info2); |
| 232 | } |
| 233 | |
| 234 | BOOST_AUTO_TEST_CASE(OperatorEqualsDifferentTypes) |
| 235 | { |
| 236 | SigningInfo info1("key:/my-id/KEY/1"); |
| 237 | SigningInfo info2("key:/my-id/KEY/1"); |
| 238 | // Check equality for key type |
| 239 | BOOST_CHECK_EQUAL(info1, info2); |
| 240 | info2 = SigningInfo("id:/my-id"); |
| 241 | // Change signature type, check inequality |
| 242 | BOOST_CHECK_NE(info1, info2); |
| 243 | info2 = SigningInfo("key:/not-same-id/KEY/1"); |
| 244 | // Change key name, check inequality |
| 245 | BOOST_CHECK_NE(info1, info2); |
| 246 | |
| 247 | info1 = SigningInfo("cert:/my-id/KEY/1/self/%FD01"); |
| 248 | info2 = SigningInfo("cert:/my-id/KEY/1/self/%FD01"); |
| 249 | // Check equality for cert type |
| 250 | BOOST_CHECK_EQUAL(info1, info2); |
| 251 | info2 = SigningInfo("cert:/not-my-id/KEY/1/other/%FD01"); |
| 252 | // Change cert name, check inequality |
| 253 | BOOST_CHECK_NE(info1, info2); |
| 254 | info2 = SigningInfo("id:/my-id"); |
| 255 | // Change signature type, check inequality |
| 256 | BOOST_CHECK_NE(info1, info2); |
| 257 | |
| 258 | info1 = SigningInfo(SigningInfo::SIGNER_TYPE_NULL); |
| 259 | info2 = SigningInfo(SigningInfo::SIGNER_TYPE_NULL); |
| 260 | // Check equality for null type |
| 261 | BOOST_CHECK_EQUAL(info1, info2); |
| 262 | info2 = SigningInfo("id:/my-id"); |
| 263 | // Change signature type, check inequality |
| 264 | BOOST_CHECK_NE(info1, info2); |
| 265 | |
| 266 | info1 = SigningInfo(SigningInfo::SIGNER_TYPE_SHA256); |
| 267 | info2 = SigningInfo(SigningInfo::SIGNER_TYPE_SHA256); |
| 268 | // Check equality for SHA256 digest type |
| 269 | BOOST_CHECK_EQUAL(info1, info2); |
| 270 | info2 = SigningInfo("id:/my-id"); |
| 271 | // Change signature type, check inequality |
| 272 | BOOST_CHECK_NE(info1, info2); |
Eric Newberry | b74bbda | 2020-06-18 19:33:58 -0700 | [diff] [blame] | 273 | |
| 274 | info1 = SigningInfo(SigningInfo::SIGNER_TYPE_SHA256); |
| 275 | info2 = SigningInfo(SigningInfo::SIGNER_TYPE_SHA256); |
| 276 | // Check equality for signed Interest format |
| 277 | BOOST_CHECK_EQUAL(info1, info2); |
| 278 | info2.setSignedInterestFormat(SignedInterestFormat::V03); |
| 279 | // Change signed Interest format, check inequality |
| 280 | BOOST_CHECK_NE(info1, info2); |
Nick Gordon | 2a6d45a | 2017-01-25 14:10:44 -0600 | [diff] [blame] | 281 | } |
| 282 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame] | 283 | BOOST_AUTO_TEST_SUITE_END() // TestSigningInfo |
| 284 | BOOST_AUTO_TEST_SUITE_END() // Security |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 285 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 286 | } // namespace ndn::tests |