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 encryption-decryption-env.h
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
26 #include <condition_variable>
28 #include <ckmc/ckmc-type.h>
29 #include <ckmc/ckmc-manager.h>
30 #include <ckm/ckm-manager-async.h>
43 virtual EncryptionError encrypt(ckmc_param_list_h params,
44 const char *key_alias,
46 const ckmc_raw_buffer_s& decrypted,
47 ckmc_raw_buffer_s **ppencrypted) = 0;
49 virtual EncryptionError decrypt(ckmc_param_list_h params,
50 const char *key_alias,
52 const ckmc_raw_buffer_s& encrypted,
53 ckmc_raw_buffer_s **ppdecrypted) = 0;
56 class SyncApi : public EncryptionApi
59 virtual EncryptionError encrypt(ckmc_param_list_h params,
60 const char *key_alias,
62 const ckmc_raw_buffer_s& decrypted,
63 ckmc_raw_buffer_s **ppencrypted);
65 virtual EncryptionError decrypt(ckmc_param_list_h params,
66 const char *key_alias,
68 const ckmc_raw_buffer_s& encrypted,
69 ckmc_raw_buffer_s **ppdecrypted);
71 static EncryptionError ckmcError2Result(int error);
74 struct AsyncApi : public EncryptionApi
77 struct Observer : public CKM::ManagerAsync::Observer {
78 Observer() : m_finished(false), m_error(CKM_API_SUCCESS) {}
80 void ReceivedError(int error);
81 void ReceivedEncrypted(CKM::RawBuffer && buffer);
82 void ReceivedDecrypted(CKM::RawBuffer && buffer);
83 void WaitForResponse();
84 void Finished(int error = CKMC_ERROR_NONE);
87 std::condition_variable m_cv;
90 CKM::RawBuffer m_buffer;
94 EncryptionError encrypt(ckmc_param_list_h params,
95 const char *key_alias,
97 const ckmc_raw_buffer_s& decrypted,
98 ckmc_raw_buffer_s **ppencrypted);
100 EncryptionError decrypt(ckmc_param_list_h params,
101 const char *key_alias,
102 const char *password,
103 const ckmc_raw_buffer_s& encrypted,
104 ckmc_raw_buffer_s **ppdecrypted);
106 typedef void (CKM::ManagerAsync::*cryptoFn)(const CKM::ManagerAsync::ObserverPtr&,
107 const CKM::CryptoAlgorithm&,
109 const CKM::Password&,
110 const CKM::RawBuffer&);
112 EncryptionError crypt(cryptoFn operation,
113 ckmc_param_list_h params,
114 const char *key_alias,
115 const char *password,
116 const ckmc_raw_buffer_s& in,
117 ckmc_raw_buffer_s **ppout);
119 static EncryptionError ckmError2Result(int error);