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