blob: d3311beb2b6cc54da0172f8919e54245c0e56221 [file] [log] [blame]
Yingdi Yu1b0311c2015-06-10 14:58:47 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2015 Regents of the University of California.
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
22#include "security/signing-info.hpp"
23
24#include "boost-test.hpp"
25
26namespace ndn {
27namespace security {
28namespace tests {
29
30BOOST_AUTO_TEST_SUITE(SecuritySigningInfo)
31
32BOOST_AUTO_TEST_CASE(Basic)
33{
34 Name id("/id");
35 Name key("/key");
36 Name cert("/cert");
37
38 SigningInfo info;
39
40 BOOST_CHECK_EQUAL(info.getSignerType(), SigningInfo::SIGNER_TYPE_NULL);
41 BOOST_CHECK_EQUAL(info.getSignerName(), SigningInfo::EMPTY_NAME);
42 BOOST_CHECK_EQUAL(info.getDigestAlgorithm(), DIGEST_ALGORITHM_SHA256);
43
44 const SignatureInfo& sigInfo = info.getSignatureInfo();
45 BOOST_CHECK_EQUAL(sigInfo.getSignatureType(), -1);
46 BOOST_CHECK_EQUAL(sigInfo.hasKeyLocator(), false);
47
48 info.setSigningIdentity(id);
49 BOOST_CHECK_EQUAL(info.getSignerType(), SigningInfo::SIGNER_TYPE_ID);
50 BOOST_CHECK_EQUAL(info.getSignerName(), id);
51
52 SigningInfo infoId(SigningInfo::SIGNER_TYPE_ID, id);
53 BOOST_CHECK_EQUAL(infoId.getSignerType(), SigningInfo::SIGNER_TYPE_ID);
54 BOOST_CHECK_EQUAL(infoId.getSignerName(), id);
55
56 info.setSigningKeyName(key);
57 BOOST_CHECK_EQUAL(info.getSignerType(), SigningInfo::SIGNER_TYPE_KEY);
58 BOOST_CHECK_EQUAL(info.getSignerName(), key);
59
60 SigningInfo infoKey(SigningInfo::SIGNER_TYPE_KEY, key);
61 BOOST_CHECK_EQUAL(infoKey.getSignerType(), SigningInfo::SIGNER_TYPE_KEY);
62 BOOST_CHECK_EQUAL(infoKey.getSignerName(), key);
63
64 info.setSigningCertName(cert);
65 BOOST_CHECK_EQUAL(info.getSignerType(), SigningInfo::SIGNER_TYPE_CERT);
66 BOOST_CHECK_EQUAL(info.getSignerName(), cert);
67
68 SigningInfo infoCert(SigningInfo::SIGNER_TYPE_CERT, cert);
69 BOOST_CHECK_EQUAL(infoCert.getSignerType(), SigningInfo::SIGNER_TYPE_CERT);
70 BOOST_CHECK_EQUAL(infoCert.getSignerName(), cert);
71
72 info.setSha256Signing();
73 BOOST_CHECK_EQUAL(info.getSignerType(), SigningInfo::SIGNER_TYPE_SHA256);
74 BOOST_CHECK_EQUAL(info.getSignerName(), SigningInfo::EMPTY_NAME);
75
76 SigningInfo infoSha(SigningInfo::SIGNER_TYPE_SHA256);
77 BOOST_CHECK_EQUAL(infoSha.getSignerType(), SigningInfo::SIGNER_TYPE_SHA256);
78 BOOST_CHECK_EQUAL(infoSha.getSignerName(), SigningInfo::EMPTY_NAME);
79}
80
81BOOST_AUTO_TEST_CASE(CustomSignatureInfo)
82{
83 SigningInfo info1;
84 BOOST_CHECK(info1.getSignatureInfo() == SignatureInfo());
85
86 SignatureInfo si;
87 si.setKeyLocator(Name("ndn:/test/key/locator"));
88 info1.setSignatureInfo(si);
89
90 BOOST_CHECK(info1.getSignatureInfo() == si);
91
92 SigningInfo info2(SigningInfo::SIGNER_TYPE_NULL, SigningInfo::EMPTY_NAME, si);
93 BOOST_CHECK(info2.getSignatureInfo() == si);
94}
95
96BOOST_AUTO_TEST_SUITE_END()
97
98} // namespace tests
99} // namespace security
100} // namespace ndn