/* * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ #include #include #include #include namespace { const std::string PUBKEY_PEM = "-----BEGIN PUBLIC KEY-----\n" "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0EJRdUtd2th0vTVF7Qxv\n" "DKzyFCF3w9vC9IDE/Yr12w+a9jd0s7/eG96qTHIYffS3B7x2MB+d4n+SR3W0qmYh\n" "7xk8qfEgH3daeDoV59IZ9r543KM+g8jm6KffYGX1bIJVVY5OhBRbO9nY6byYpd5k\n" "bCIUB6dCf7/WrQl1aIdLGFIegAzPGFPXDcU6F192686x54bxt/itMX4agHJ9ZC/r\n" "rTBIZghVsjJo5/AH5WZpasv8sfrGiiohAxtieoYoJkv5MOYP4/2lPlOY+Cgw1Yoz\n" "+HHv31AllgFsBquBb/kJVmCCNsAOcnvQzTZUsW/TXz9G2nwRdqI1nSy2JvVjZGsq\n" "GQIDAQAB\n" "-----END PUBLIC KEY-----\n"; } using namespace CKM; BOOST_AUTO_TEST_SUITE(KEY_TEST) BOOST_AUTO_TEST_CASE(constructors) { RawBuffer keybuf(PUBKEY_PEM.begin(), PUBKEY_PEM.end()); KeyImpl key(keybuf); BOOST_REQUIRE(!key.empty()); // valid key type case BOOST_REQUIRE(!KeyImpl(key.getEvpShPtr(), KeyType::KEY_RSA_PUBLIC).empty()); // invalid key type cases BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_DSA_PUBLIC).empty()); BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_DSA_PRIVATE).empty()); BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_ECDSA_PUBLIC).empty()); BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_ECDSA_PRIVATE).empty()); BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), KeyType::KEY_AES).empty()); BOOST_REQUIRE(KeyImpl(key.getEvpShPtr(), static_cast(999999)).empty()); } BOOST_AUTO_TEST_CASE(get_size) { RawBuffer keybuf(PUBKEY_PEM.begin(), PUBKEY_PEM.end()); KeyImpl key(keybuf); BOOST_REQUIRE(!key.empty()); // not ipmlemented yet but test for coverage. It'll just return 0 BOOST_REQUIRE_NO_THROW(key.getSize()); } BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE(AES_KEY_TEST) BOOST_AUTO_TEST_CASE(constructors) { // invalid key size RawBuffer keybuf({0x01, 0x02, 0x03, 0x04}); BOOST_REQUIRE(!Key::createAES(keybuf)); keybuf.clear(); for (size_t i = 0; i < 16; ++i) keybuf.push_back(i); BOOST_REQUIRE(Key::createAES(keybuf)); keybuf.clear(); for (size_t i = 0; i < 24; ++i) keybuf.push_back(i); BOOST_REQUIRE(Key::createAES(keybuf)); keybuf.clear(); for (size_t i = 0; i < 32; ++i) keybuf.push_back(i); BOOST_REQUIRE(Key::createAES(keybuf)); } BOOST_AUTO_TEST_SUITE_END()