sync with tizen_2.0
[platform/framework/native/appfw.git] / src / security / FSecPrivateKey.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                FSecPrivateKey.cpp
20  * @brief               This is the implementation file for PrivateKey class.
21  *
22  * This header file contains the implementation of PrivateKey class.
23  */
24 #include <unique_ptr.h>
25 #include <FBaseResult.h>
26 #include <FSecPrivateKey.h>
27 #include <FBaseSysLog.h>
28
29 using namespace Tizen::Base;
30
31
32 namespace Tizen { namespace Security
33 {
34
35 PrivateKey::PrivateKey(void)
36         : __pPrivateKeyImpl(null)
37 {
38         __algorithm = L"RSA";
39         __encodedFormat = L"ASN.1";
40 }
41
42 PrivateKey::~PrivateKey(void)
43 {
44 }
45
46 String
47 PrivateKey::GetFormat(void) const
48 {
49         return __encodedFormat;
50 }
51
52 ByteBuffer*
53 PrivateKey::GetEncodedN(void) const
54 {
55         result r = E_SUCCESS;
56
57         ClearLastResult();
58
59         std::unique_ptr<ByteBuffer> pKeyBuffer(new (std::nothrow) ByteBuffer());
60         SysTryReturn(NID_SEC, pKeyBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
61
62         r = pKeyBuffer->Construct(__keyBytes);
63         SysTryReturn(NID_SEC, !IsFailed(r), null, r, "[%s] Input key buffer is not valid.", GetErrorMessage(r));
64
65         return pKeyBuffer.release();
66 }
67
68 result
69 PrivateKey::SetKey(const ByteBuffer& keyBuffer)
70 {
71         return __keyBytes.Construct(keyBuffer);
72 }
73
74 } } //Tizen::Security