Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2015 Regents of the University of California. |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53: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 | |
| 22 | #include "security/key-params.hpp" |
| 23 | |
| 24 | #include "boost-test.hpp" |
| 25 | |
| 26 | |
| 27 | namespace ndn { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 28 | namespace tests { |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 29 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 30 | BOOST_AUTO_TEST_SUITE(SecurityKeyParams) |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 31 | |
| 32 | BOOST_AUTO_TEST_CASE(RsaParameter) |
| 33 | { |
| 34 | RsaKeyParams params; |
| 35 | BOOST_CHECK_EQUAL(params.getKeyType(), KEY_TYPE_RSA); |
| 36 | BOOST_CHECK_EQUAL(params.getKeySize(), 2048); |
| 37 | |
| 38 | RsaKeyParams params2(1024); |
| 39 | BOOST_CHECK_EQUAL(params2.getKeyType(), KEY_TYPE_RSA); |
| 40 | BOOST_CHECK_EQUAL(params2.getKeySize(), 1024); |
| 41 | |
| 42 | RsaKeyParams params3(3); |
| 43 | BOOST_CHECK_EQUAL(params3.getKeyType(), KEY_TYPE_RSA); |
| 44 | BOOST_CHECK_EQUAL(params3.getKeySize(), 2048); |
| 45 | } |
| 46 | |
| 47 | BOOST_AUTO_TEST_CASE(EcdsaParameter) |
| 48 | { |
| 49 | EcdsaKeyParams params; |
| 50 | BOOST_CHECK_EQUAL(params.getKeyType(), KEY_TYPE_ECDSA); |
| 51 | BOOST_CHECK_EQUAL(params.getKeySize(), 256); |
| 52 | |
| 53 | EcdsaKeyParams params2(384); |
| 54 | BOOST_CHECK_EQUAL(params2.getKeyType(), KEY_TYPE_ECDSA); |
| 55 | BOOST_CHECK_EQUAL(params2.getKeySize(), 384); |
| 56 | |
| 57 | EcdsaKeyParams params3(3); |
| 58 | BOOST_CHECK_EQUAL(params3.getKeyType(), KEY_TYPE_ECDSA); |
| 59 | BOOST_CHECK_EQUAL(params3.getKeySize(), 256); |
| 60 | } |
| 61 | |
| 62 | BOOST_AUTO_TEST_CASE(AesParameter) |
| 63 | { |
| 64 | AesKeyParams params; |
| 65 | BOOST_CHECK_EQUAL(params.getKeyType(), KEY_TYPE_AES); |
| 66 | BOOST_CHECK_EQUAL(params.getKeySize(), 64); |
| 67 | |
| 68 | AesKeyParams params2(128); |
| 69 | BOOST_CHECK_EQUAL(params2.getKeyType(), KEY_TYPE_AES); |
| 70 | BOOST_CHECK_EQUAL(params2.getKeySize(), 128); |
| 71 | |
| 72 | AesKeyParams params3(256); |
| 73 | BOOST_CHECK_EQUAL(params3.getKeyType(), KEY_TYPE_AES); |
| 74 | BOOST_CHECK_EQUAL(params3.getKeySize(), 256); |
| 75 | |
| 76 | AesKeyParams params4(4); |
| 77 | BOOST_CHECK_EQUAL(params4.getKeyType(), KEY_TYPE_AES); |
| 78 | BOOST_CHECK_EQUAL(params4.getKeySize(), 64); |
| 79 | } |
| 80 | |
| 81 | BOOST_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 | |
| 90 | BOOST_AUTO_TEST_SUITE_END() |
| 91 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 92 | } // namespace tests |
Yingdi Yu | 7036ce2 | 2014-06-19 18:53:37 -0700 | [diff] [blame] | 93 | } // namespace ndn |