Integration with CryptoService class.
[platform/core/security/key-manager.git] / src / manager / client / client-key.cpp
1 /* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
2  *
3  *  Licensed under the Apache License, Version 2.0 (the "License");
4  *  you may not use this file except in compliance with the License.
5  *  You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  *  Unless required by applicable law or agreed to in writing, software
10  *  distributed under the License is distributed on an "AS IS" BASIS,
11  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  *  See the License for the specific language governing permissions and
13  *  limitations under the License
14  *
15  *
16  * @file        client-key.cpp
17  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
18  * @version     1.0
19  * @brief       Key - api implementation.
20  */
21 #include <ckm/ckm-type.h>
22 #include <ckm/key-manager.h>
23
24 #include <dpl/log/log.h>
25
26 #include <key-rsa.h>
27
28 namespace CKM {
29
30 Key::Key()
31   : m_impl(NULL)
32 {}
33
34 Key::Key(
35     const RawBuffer &rawData,
36     KeyType type,
37     const std::string &password)
38 {
39     switch (type) {
40         case KeyType::KEY_RSA_PRIVATE:
41             m_impl.reset(new KeyRSAPrivate(rawData, password));
42             break;
43         case KeyType::KEY_RSA_PUBLIC:
44             m_impl.reset(new KeyRSAPublic(rawData, password));
45             break;
46         default:
47             LogError("Key Type not implemented");
48     }
49 }
50
51 Key::Key(const Key &second) {
52     m_impl = second.m_impl;
53 }
54
55 Key& Key::operator=(const Key &second) {
56     m_impl = second.m_impl;
57     return *this;
58 }
59
60 Key::~Key(){}
61
62 bool Key::empty() const {
63     if (m_impl)
64         return m_impl->empty();
65     return true;
66 }
67
68 KeyType Key::getType() const {
69     if (m_impl)
70         return m_impl->getType();
71     return KeyType::KEY_NONE;
72 }
73
74 RawBuffer Key::getDER() const {
75     if (m_impl)
76         return m_impl->getDER();
77     return RawBuffer();
78 }
79
80 GenericKey* Key::getImpl() const {
81     if (m_impl)
82         return m_impl.get();
83     return NULL;
84 };
85
86
87 } // namespace CKM
88