Release 0.1.54.9
[platform/core/security/key-manager.git] / common / test_common.cpp
1 /*
2  *  Copyright (c) 2016-2019 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  *  Contact: Kyungwook Tak <k.tak@samsung.com>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  *
18  * @file        test_common.cpp
19  * @author      Zofia Abramowska (z.abramowska@samsung.com)
20  * @version
21  * @brief
22  */
23 #include <test_common.h>
24 #include <cstdlib>
25 #include <time.h>
26
27 using namespace CKM;
28
29 RawBuffer createDefaultPass()
30 {
31         return createPass(0, RAW_PASS_SIZE);
32 }
33
34 RawBuffer createPass(std::size_t from, std::size_t to)
35 {
36         RawBuffer raw;
37
38         for (std::size_t i = from; i < to; i++)
39                 raw.push_back(static_cast<unsigned char>(i));
40
41         return raw;
42 }
43
44 RawBuffer createBigBlob(std::size_t size)
45 {
46         return createPass(0, size);
47 }
48
49 RawBuffer createRandom(std::size_t size)
50 {
51         static unsigned int seed = ::time(nullptr);
52
53         RawBuffer buf(size, 0x00);
54         for (size_t i = 0; i < size; ++i)
55                 buf[i] = static_cast<RawBuffer::value_type>(::rand_r(&seed) % 256);
56
57         return buf;
58 }
59
60 //raw to hex string conversion from SqlConnection
61 std::string rawToHexString(const RawBuffer &raw)
62 {
63         return hexDump<std::string>(raw);
64 }