2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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.
18 * @file FSecKeyPair.cpp
19 * @brief This is the implementation file for KeyPair class.
21 #include <FBaseResult.h>
22 #include <FBaseErrors.h>
23 #include <FSecKeyPair.h>
24 #include <FSecPublicKey.h>
25 #include <FSecPrivateKey.h>
26 #include <FBaseSysLog.h>
28 using namespace Tizen::Base;
29 using namespace Tizen::Security;
32 namespace Tizen { namespace Security
35 KeyPair::KeyPair(void)
38 , __pKeyPairImpl(null)
42 KeyPair::~KeyPair(void)
49 KeyPair::Construct(IPublicKey& publicKey, IPrivateKey& privateKey)
53 SysAssertf(__pPubKey == null && __pPriKey == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class");
55 __pPubKey = new (std::nothrow) PublicKey();
56 SysTryReturn(NID_SEC, __pPubKey != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
58 __pPriKey = new (std::nothrow) PrivateKey();
59 SysTryReturn(NID_SEC, __pPriKey != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
61 *__pPubKey = publicKey;
62 *__pPriKey = privateKey;
68 KeyPair::GetPublicKey(void) const
74 KeyPair::GetPrivateKey(void) const
80 KeyPair::SetPublicKey(const ByteBuffer& pubKey)
84 SysTryReturn(NID_SEC, static_cast< int >(pubKey.GetRemaining()) > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The input public key size should be positive.");
88 __pPubKey = new (std::nothrow) PublicKey();
89 SysTryReturn(NID_SEC, __pPubKey != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
91 r = __pPubKey->SetKey(pubKey);
92 SysTryReturn(NID_SEC, !IsFailed(r), r, r, "[%s] Failed to call set key operation.", GetErrorMessage(r));
98 KeyPair::SetPrivateKey(const ByteBuffer& privKey)
100 result r = E_SUCCESS;
102 SysTryReturn(NID_SEC, privKey.GetRemaining() > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The input private key size should be positive.");
106 __pPriKey = new (std::nothrow) PrivateKey();
107 SysTryReturn(NID_SEC, __pPriKey != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
109 r = __pPriKey->SetKey(privKey);
110 SysTryReturn(NID_SEC, !IsFailed(r), r, r, "[%s] Failed to do set key operation.", GetErrorMessage(r));
115 } } //Tizen::Security