2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FSecKeyPair.cpp
20 * @brief This is the implementation file for KeyPair class.
22 #include <FBaseResult.h>
23 #include <FBaseErrors.h>
24 #include <FSecKeyPair.h>
25 #include <FSecPublicKey.h>
26 #include <FSecPrivateKey.h>
27 #include <FBaseSysLog.h>
29 using namespace Tizen::Base;
30 using namespace Tizen::Security;
33 namespace Tizen { namespace Security
36 KeyPair::KeyPair(void)
39 , __pKeyPairImpl(null)
43 KeyPair::~KeyPair(void)
50 KeyPair::Construct(IPublicKey& publicKey, IPrivateKey& privateKey)
54 SysAssertf(__pPubKey == null && __pPriKey == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class");
56 __pPubKey = new (std::nothrow) PublicKey();
57 SysTryReturn(NID_SEC, __pPubKey != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
59 __pPriKey = new (std::nothrow) PrivateKey();
60 SysTryReturn(NID_SEC, __pPriKey != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
62 *__pPubKey = publicKey;
63 *__pPriKey = privateKey;
69 KeyPair::GetPublicKey(void) const
75 KeyPair::GetPrivateKey(void) const
81 KeyPair::SetPublicKey(const ByteBuffer& pubKey)
85 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.");
89 __pPubKey = new (std::nothrow) PublicKey();
90 SysTryReturn(NID_SEC, __pPubKey != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
92 r = __pPubKey->SetKey(pubKey);
93 SysTryReturn(NID_SEC, !IsFailed(r), r, r, "[%s] Failed to call set key operation.", GetErrorMessage(r));
99 KeyPair::SetPrivateKey(const ByteBuffer& privKey)
101 result r = E_SUCCESS;
103 SysTryReturn(NID_SEC, privKey.GetRemaining() > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The input private key size should be positive.");
107 __pPriKey = new (std::nothrow) PrivateKey();
108 SysTryReturn(NID_SEC, __pPriKey != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
110 r = __pPriKey->SetKey(privKey);
111 SysTryReturn(NID_SEC, !IsFailed(r), r, r, "[%s] Failed to do set key operation.", GetErrorMessage(r));
116 } } //Tizen::Security