2 * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 #include <key-aes-impl.h>
19 #include <boost/test/unit_test.hpp>
23 const std::string PUBKEY_PEM =
24 "-----BEGIN PUBLIC KEY-----\n"
25 "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0EJRdUtd2th0vTVF7Qxv\n"
26 "DKzyFCF3w9vC9IDE/Yr12w+a9jd0s7/eG96qTHIYffS3B7x2MB+d4n+SR3W0qmYh\n"
27 "7xk8qfEgH3daeDoV59IZ9r543KM+g8jm6KffYGX1bIJVVY5OhBRbO9nY6byYpd5k\n"
28 "bCIUB6dCf7/WrQl1aIdLGFIegAzPGFPXDcU6F192686x54bxt/itMX4agHJ9ZC/r\n"
29 "rTBIZghVsjJo5/AH5WZpasv8sfrGiiohAxtieoYoJkv5MOYP4/2lPlOY+Cgw1Yoz\n"
30 "+HHv31AllgFsBquBb/kJVmCCNsAOcnvQzTZUsW/TXz9G2nwRdqI1nSy2JvVjZGsq\n"
32 "-----END PUBLIC KEY-----\n";
37 BOOST_AUTO_TEST_SUITE(KEY_TEST)
39 BOOST_AUTO_TEST_CASE(constructors)
41 RawBuffer keybuf(PUBKEY_PEM.begin(), PUBKEY_PEM.end());
44 BOOST_REQUIRE(!key.empty());
46 // valid key type case
47 BOOST_REQUIRE(!KeyImpl(key.getEvpShPtr(), KeyType::KEY_RSA_PUBLIC).empty());
49 // invalid key type cases
50 BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_DSA_PUBLIC).empty());
51 BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_DSA_PRIVATE).empty());
52 BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_ECDSA_PUBLIC).empty());
53 BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_ECDSA_PRIVATE).empty());
54 BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_AES).empty());
55 BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), static_cast<KeyType>(999999)).empty());
58 BOOST_AUTO_TEST_CASE(get_size)
60 RawBuffer keybuf(PUBKEY_PEM.begin(), PUBKEY_PEM.end());
63 BOOST_REQUIRE(!key.empty());
65 // not ipmlemented yet but test for coverage. It'll just return 0
66 BOOST_REQUIRE_NO_THROW(key.getSize());
69 BOOST_AUTO_TEST_SUITE_END()
71 BOOST_AUTO_TEST_SUITE(AES_KEY_TEST)
73 BOOST_AUTO_TEST_CASE(constructors)
76 RawBuffer keybuf({0x01, 0x02, 0x03, 0x04});
77 BOOST_REQUIRE(!Key::createAES(keybuf));
80 for (size_t i = 0; i < 16; ++i)
82 BOOST_REQUIRE(Key::createAES(keybuf));
85 for (size_t i = 0; i < 24; ++i)
87 BOOST_REQUIRE(Key::createAES(keybuf));
90 for (size_t i = 0; i < 32; ++i)
92 BOOST_REQUIRE(Key::createAES(keybuf));
95 BOOST_AUTO_TEST_SUITE_END()