1 /* Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * @file client-manager-impl.cpp
17 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19 * @brief Manager implementation.
23 #include <ckm/key-manager.h>
27 class Manager::ManagerImpl {
32 virtual ~ManagerImpl(){}
34 int saveKey(const Alias &alias, const Key &key, const Policy &policy) {
37 return try_catch([&] {
38 if (user.empty() || key.empty())
39 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
42 Serialization::Serialization(send, static_cast<int>(StorageCommand::SAVE_KEY));
43 Serialization::Serialize(send, m_counter);
44 Serialization::Serialize(send, alias);
45 Serialization::Serialize(send, key.getImpl());
46 Serialization::Serialize(send, policy);
48 int retCode = sendToServer(
49 SERVICE_SOCKET_CKM_STORAGE,
53 if (KEY_MANAGER_API_SUCCESS != retCode) {
58 Deserialization::Deserialize(recv, id);
59 Deserialization::Deserialize(recv, retCode);
61 if (id != m_counter) {
62 return KEY_MANAGER_API_ERROR_UNKNOWN;
69 int removeKey(const Alias &alias) {
70 return try_catch([&] {
71 if (user.empty() || key.empty())
72 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
75 Serialization::Serialization(send, static_cast<int>(StorageCommand::REMOVE_KEY));
76 Serialization::Serialize(send, m_counter);
77 Serialization::Serialize(send, alias);
79 int retCode = sendToServer(
80 SERVICE_SOCKET_CKM_STORAGE,
84 if (KEY_MANAGER_API_SUCCESS != retCode) {
89 Deserialization::Deserialize(recv, id);
90 Deserialization::Deserialize(recv, retCode);
92 if (id != m_counter) {
93 return KEY_MANAGER_API_ERROR_UNKNOWN;
99 int getKey(const Alias &alias, const RawData &password, Key &key) {
100 return try_catch([&] {
101 if (user.empty() || key.empty())
102 return KEY_MANAGER_API_ERROR_INPUT_PARAM;
105 Serialization::Serialization(send, static_cast<int>(StorageCommand::REMOVE_KEY));
106 Serialization::Serialize(send, m_counter);
107 Serialization::Serialize(send, alias);
108 Serialization::Serialize(send, password);
109 Serialization::Serialize(send, key.getImpl());
111 int retCode = sendToServer(
112 SERVICE_SOCKET_CKM_STORAGE,
116 if (KEY_MANAGER_API_SUCCESS != retCode) {
121 Deserialization::Deserialize(recv, id);
122 Deserialization::Deserialize(recv, retCode);
124 if (id != m_counter) {
125 return KEY_MANAGER_API_ERROR_UNKNOWN;