blob: 66e30fee7af41ee000bafa1ea2384671fe0e854e [file] [log] [blame]
Yingdi Yu7036ce22014-06-19 18:53:37 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yingdi Yu99b2a002015-08-12 12:47:44 -07003 * Copyright (c) 2013-2016 Regents of the University of California.
Yingdi Yu7036ce22014-06-19 18:53:37 -07004 *
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/key-params.hpp"
23
24#include "boost-test.hpp"
25
26
27namespace ndn {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080028namespace tests {
Yingdi Yu7036ce22014-06-19 18:53:37 -070029
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080030BOOST_AUTO_TEST_SUITE(SecurityKeyParams)
Yingdi Yu7036ce22014-06-19 18:53:37 -070031
32BOOST_AUTO_TEST_CASE(RsaParameter)
33{
34 RsaKeyParams params;
Yingdi Yu99b2a002015-08-12 12:47:44 -070035 BOOST_CHECK_EQUAL(params.getKeyType(), KeyType::RSA);
Yingdi Yu7036ce22014-06-19 18:53:37 -070036 BOOST_CHECK_EQUAL(params.getKeySize(), 2048);
37
38 RsaKeyParams params2(1024);
Yingdi Yu99b2a002015-08-12 12:47:44 -070039 BOOST_CHECK_EQUAL(params2.getKeyType(), KeyType::RSA);
Yingdi Yu7036ce22014-06-19 18:53:37 -070040 BOOST_CHECK_EQUAL(params2.getKeySize(), 1024);
41
42 RsaKeyParams params3(3);
Yingdi Yu99b2a002015-08-12 12:47:44 -070043 BOOST_CHECK_EQUAL(params3.getKeyType(), KeyType::RSA);
Yingdi Yu7036ce22014-06-19 18:53:37 -070044 BOOST_CHECK_EQUAL(params3.getKeySize(), 2048);
45}
46
47BOOST_AUTO_TEST_CASE(EcdsaParameter)
48{
49 EcdsaKeyParams params;
Yingdi Yu99b2a002015-08-12 12:47:44 -070050 BOOST_CHECK_EQUAL(params.getKeyType(), KeyType::EC);
Yingdi Yu7036ce22014-06-19 18:53:37 -070051 BOOST_CHECK_EQUAL(params.getKeySize(), 256);
52
53 EcdsaKeyParams params2(384);
Yingdi Yu99b2a002015-08-12 12:47:44 -070054 BOOST_CHECK_EQUAL(params2.getKeyType(), KeyType::EC);
Yingdi Yu7036ce22014-06-19 18:53:37 -070055 BOOST_CHECK_EQUAL(params2.getKeySize(), 384);
56
57 EcdsaKeyParams params3(3);
Yingdi Yu99b2a002015-08-12 12:47:44 -070058 BOOST_CHECK_EQUAL(params3.getKeyType(), KeyType::EC);
Yingdi Yu7036ce22014-06-19 18:53:37 -070059 BOOST_CHECK_EQUAL(params3.getKeySize(), 256);
60}
61
62BOOST_AUTO_TEST_CASE(AesParameter)
63{
64 AesKeyParams params;
Yingdi Yu99b2a002015-08-12 12:47:44 -070065 BOOST_CHECK_EQUAL(params.getKeyType(), KeyType::AES);
Yingdi Yu7036ce22014-06-19 18:53:37 -070066 BOOST_CHECK_EQUAL(params.getKeySize(), 64);
67
68 AesKeyParams params2(128);
Yingdi Yu99b2a002015-08-12 12:47:44 -070069 BOOST_CHECK_EQUAL(params2.getKeyType(), KeyType::AES);
Yingdi Yu7036ce22014-06-19 18:53:37 -070070 BOOST_CHECK_EQUAL(params2.getKeySize(), 128);
71
72 AesKeyParams params3(256);
Yingdi Yu99b2a002015-08-12 12:47:44 -070073 BOOST_CHECK_EQUAL(params3.getKeyType(), KeyType::AES);
Yingdi Yu7036ce22014-06-19 18:53:37 -070074 BOOST_CHECK_EQUAL(params3.getKeySize(), 256);
75
76 AesKeyParams params4(4);
Yingdi Yu99b2a002015-08-12 12:47:44 -070077 BOOST_CHECK_EQUAL(params4.getKeyType(), KeyType::AES);
Yingdi Yu7036ce22014-06-19 18:53:37 -070078 BOOST_CHECK_EQUAL(params4.getKeySize(), 64);
79}
80
81BOOST_AUTO_TEST_CASE(Error)
82{
83 EcdsaKeyParams params;
84 BOOST_REQUIRE_THROW((RsaKeyParams(params)), KeyParams::Error);
85
86 AesKeyParams params2;
87 BOOST_REQUIRE_THROW((RsaKeyParams(params2)), KeyParams::Error);
88}
89
90BOOST_AUTO_TEST_SUITE_END()
91
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080092} // namespace tests
Yingdi Yu7036ce22014-06-19 18:53:37 -070093} // namespace ndn