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