Merge "Fixed Klocworks issues" into devel_3.0_main
[platform/framework/native/appfw.git] / src / security / FSecSecretKey.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                FSecSecretKey.cpp
19  * @brief               This is the implementation file for SecretKey class.
20  */
21 #include <unique_ptr.h>
22 #include <FBaseResult.h>
23 #include <FBaseErrors.h>
24 #include <FSecSecretKey.h>
25 #include <FBaseSysLog.h>
26
27 using namespace Tizen::Base;
28
29
30 namespace Tizen { namespace Security
31 {
32
33 SecretKey::SecretKey(void)
34         : __pSecretKeyImpl(null)
35 {
36 }
37
38 SecretKey::~SecretKey(void)
39 {
40 }
41
42 String
43 SecretKey::GetFormat(void) const
44 {
45         String encodedFormat = L"NONE";
46
47         return encodedFormat;
48 }
49
50 ByteBuffer*
51 SecretKey::GetEncodedN(void) const
52 {
53         result r = E_SUCCESS;
54
55         ClearLastResult();
56
57         std::unique_ptr<ByteBuffer> pKeyBuffer(new (std::nothrow) ByteBuffer());
58         SysTryReturn(NID_SEC, pKeyBuffer != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory");
59
60         r = pKeyBuffer->Construct(__keyBytes);
61         SysTryReturn(NID_SEC, !IsFailed(r), null, r, "[%s] Input key buffer is not valid.", GetErrorMessage(r));
62
63         return pKeyBuffer.release();
64 }
65
66 result
67 SecretKey::SetKey(const ByteBuffer& keyBuffer)
68 {
69         //Store the secret key
70         return __keyBytes.Construct(keyBuffer);
71 }
72
73 } } //Tizen::Security