2 * Copyright (c) 2016 - 2019 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
16 * @file test_data-type.cpp
17 * @author Kyungwook Tak (k.tak@samsung.com)
19 * @brief DataType class test
21 #include <data-type.h>
23 #include <boost/test/unit_test.hpp>
25 #include <ckm/ckm-type.h>
26 #include <exception.h>
32 BOOST_AUTO_TEST_SUITE(DATA_TYPE_TEST)
34 BOOST_AUTO_TEST_CASE(CONSTRUCTOR)
36 BOOST_REQUIRE_THROW(DataType(static_cast<DataType::Type>(999)),
37 CKM::Exc::InputParam);
38 BOOST_REQUIRE_THROW(DataType(static_cast<KeyType>(999)),
39 CKM::Exc::InputParam);
42 BOOST_AUTO_TEST_CASE(KEY_TYPE_CASTING)
44 std::vector<std::pair<DataType, KeyType>> pairs;
46 pairs.emplace_back(DataType::KEY_RSA_PUBLIC, KeyType::KEY_RSA_PUBLIC);
47 pairs.emplace_back(DataType::KEY_RSA_PRIVATE, KeyType::KEY_RSA_PRIVATE);
49 pairs.emplace_back(DataType::KEY_DSA_PUBLIC, KeyType::KEY_DSA_PUBLIC);
50 pairs.emplace_back(DataType::KEY_DSA_PRIVATE, KeyType::KEY_DSA_PRIVATE);
52 pairs.emplace_back(DataType::KEY_ECDSA_PUBLIC, KeyType::KEY_ECDSA_PUBLIC);
53 pairs.emplace_back(DataType::KEY_ECDSA_PRIVATE, KeyType::KEY_ECDSA_PRIVATE);
55 pairs.emplace_back(DataType::KEY_AES, KeyType::KEY_AES);
58 BOOST_REQUIRE(p.second == DataType(static_cast<KeyType>(p.first)));
61 BOOST_AUTO_TEST_CASE(UNARY_OPERATIONS)
63 BOOST_REQUIRE(DataType(DataType::KEY_AES).isSKey());
64 BOOST_REQUIRE(!DataType(DataType::KEY_RSA_PUBLIC).isSKey());
66 BOOST_REQUIRE(DataType(DataType::DB_CHAIN_FIRST).isChainCert());
67 BOOST_REQUIRE(DataType(DataType::DB_CHAIN_LAST).isChainCert());
68 BOOST_REQUIRE(!DataType(DataType::KEY_AES).isChainCert());
70 BOOST_REQUIRE(DataType(DataType::KEY_RSA_PUBLIC).isKeyPublic());
71 BOOST_REQUIRE(DataType(DataType::KEY_DSA_PUBLIC).isKeyPublic());
72 BOOST_REQUIRE(DataType(DataType::KEY_ECDSA_PUBLIC).isKeyPublic());
73 BOOST_REQUIRE(!DataType(DataType::KEY_RSA_PRIVATE).isKeyPublic());
74 BOOST_REQUIRE(!DataType(DataType::KEY_DSA_PRIVATE).isKeyPublic());
75 BOOST_REQUIRE(!DataType(DataType::KEY_ECDSA_PRIVATE).isKeyPublic());
76 BOOST_REQUIRE(!DataType(DataType::KEY_AES).isKeyPublic());
77 BOOST_REQUIRE(!DataType(DataType::DB_CHAIN_LAST).isKeyPublic());
79 BOOST_REQUIRE(DataType(DataType::KEY_RSA_PRIVATE).isKeyPrivate());
80 BOOST_REQUIRE(DataType(DataType::KEY_DSA_PRIVATE).isKeyPrivate());
81 BOOST_REQUIRE(DataType(DataType::KEY_ECDSA_PRIVATE).isKeyPrivate());
82 BOOST_REQUIRE(!DataType(DataType::KEY_RSA_PUBLIC).isKeyPrivate());
83 BOOST_REQUIRE(!DataType(DataType::KEY_DSA_PUBLIC).isKeyPrivate());
84 BOOST_REQUIRE(!DataType(DataType::KEY_ECDSA_PUBLIC).isKeyPrivate());
85 BOOST_REQUIRE(!DataType(DataType::KEY_AES).isKeyPrivate());
86 BOOST_REQUIRE(!DataType(DataType::DB_CHAIN_FIRST).isKeyPrivate());
88 BOOST_REQUIRE(DataType(DataType::CERTIFICATE).isCertificate());
89 BOOST_REQUIRE(!DataType(DataType::KEY_AES).isCertificate());
90 BOOST_REQUIRE(!DataType().isCertificate());
91 BOOST_REQUIRE(!DataType(DataType::DB_CHAIN_FIRST).isCertificate());
93 BOOST_REQUIRE(DataType().isBinaryData());
94 BOOST_REQUIRE(DataType(DataType::BINARY_DATA).isBinaryData());
95 BOOST_REQUIRE(!DataType(DataType::KEY_AES).isBinaryData());
96 BOOST_REQUIRE(!DataType(DataType::KEY_RSA_PUBLIC).isBinaryData());
97 BOOST_REQUIRE(!DataType(DataType::DB_CHAIN_LAST).isBinaryData());
99 BOOST_REQUIRE(DataType(DataType::DB_KEY_FIRST).isKey());
100 BOOST_REQUIRE(DataType(DataType::DB_KEY_LAST).isKey());
101 BOOST_REQUIRE(DataType(DataType::KEY_AES).isKey());
102 BOOST_REQUIRE(DataType(DataType::KEY_RSA_PUBLIC).isKey());
103 BOOST_REQUIRE(DataType(DataType::KEY_RSA_PRIVATE).isKey());
104 BOOST_REQUIRE(DataType(DataType::KEY_DSA_PUBLIC).isKey());
105 BOOST_REQUIRE(DataType(DataType::KEY_DSA_PRIVATE).isKey());
106 BOOST_REQUIRE(DataType(DataType::KEY_ECDSA_PUBLIC).isKey());
107 BOOST_REQUIRE(DataType(DataType::KEY_ECDSA_PRIVATE).isKey());
108 BOOST_REQUIRE(!DataType(DataType::DB_CHAIN_FIRST).isKey());
109 BOOST_REQUIRE(!DataType(DataType::CERTIFICATE).isKey());
110 BOOST_REQUIRE(!DataType().isKey());
113 BOOST_AUTO_TEST_CASE(GET_CHAIN_TYPE)
117 BOOST_REQUIRE(type.getChainDatatype(0) == DataType(DataType::DB_CHAIN_FIRST));
118 BOOST_REQUIRE(type.getChainDatatype(5) == DataType(DataType::CHAIN_CERT_5));
119 BOOST_REQUIRE(type.getChainDatatype(8) == DataType(DataType::CHAIN_CERT_8));
120 BOOST_REQUIRE(type.getChainDatatype(13) == DataType(DataType::CHAIN_CERT_13));
121 BOOST_REQUIRE(type.getChainDatatype(15) == DataType(DataType::DB_CHAIN_LAST));
123 BOOST_REQUIRE_THROW(type.getChainDatatype(16), CKM::Exc::InputParam);
126 BOOST_AUTO_TEST_SUITE_END()