2 * Copyright (c) 2000 - 2015 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 * @file KeyHandler.cpp
18 * @author Maciej Karpiuk (m.karpiuk2@samsung.com)
20 * @brief KeyHandler class implementation.
26 #include <KeyHandler.h>
27 #include <InitialValueHandler.h>
28 #include <ckm/ckm-type.h>
32 const char * const XML_ATTR_TYPE = "type";
33 const char * const XML_ATTR_TYPE_VAL_RSA_PRV = "RSA_PRV";
34 const char * const XML_ATTR_TYPE_VAL_RSA_PUB = "RSA_PUB";
35 const char * const XML_ATTR_TYPE_VAL_DSA_PRV = "DSA_PRV";
36 const char * const XML_ATTR_TYPE_VAL_DSA_PUB = "DSA_PUB";
37 const char * const XML_ATTR_TYPE_VAL_ECDSA_PRV = "ECDSA_PRV";
38 const char * const XML_ATTR_TYPE_VAL_ECDSA_PUB = "ECDSA_PUB";
39 const char * const XML_ATTR_TYPE_VAL_AES = "AES";
43 namespace InitialValues {
45 KeyHandler::~KeyHandler() {}
47 void KeyHandler::Start(const XML::Parser::Attributes &attr)
49 InitialValueHandler::Start(attr);
52 if(attr.find(XML_ATTR_TYPE) != attr.end())
53 m_keyType = KeyHandler::parseType(attr.at(XML_ATTR_TYPE));
56 KeyType KeyHandler::parseType(const std::string & typeStr)
58 if (typeStr == XML_ATTR_TYPE_VAL_RSA_PRV) return KeyType::KEY_RSA_PRIVATE;
59 else if(typeStr == XML_ATTR_TYPE_VAL_RSA_PUB) return KeyType::KEY_RSA_PUBLIC;
60 else if(typeStr == XML_ATTR_TYPE_VAL_DSA_PRV) return KeyType::KEY_DSA_PRIVATE;
61 else if(typeStr == XML_ATTR_TYPE_VAL_DSA_PUB) return KeyType::KEY_DSA_PUBLIC;
62 else if(typeStr == XML_ATTR_TYPE_VAL_ECDSA_PRV) return KeyType::KEY_ECDSA_PRIVATE;
63 else if(typeStr == XML_ATTR_TYPE_VAL_ECDSA_PUB) return KeyType::KEY_ECDSA_PUBLIC;
64 else if(typeStr == XML_ATTR_TYPE_VAL_AES) return KeyType::KEY_AES;
65 else // should not happen
66 throw std::runtime_error("error: invalid value discovered as key type");
69 DataType KeyHandler::getDataType() const
71 return DataType(m_keyType);