• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef UTIL_JS_UUID_H_
17 #define UTIL_JS_UUID_H_
18 
19 #include <cstring>
20 #include <iostream>
21 #include <iomanip>
22 #include <openssl/rand.h>
23 #include <queue>
24 #include <sys/sysinfo.h>
25 #include <unistd.h>
26 
27 #include "napi/native_api.h"
28 #include "napi/native_node_api.h"
29 
30 namespace OHOS::Util {
31 constexpr const int UUID_SIZE = 16;
32 struct UUID {
33     unsigned char elements[16] = {0};
34 };
35 
36 enum ConvertFlags {
37     HEX_ZERO_FLG = 0x0,
38     HEX_ONE_FLG = 0x1,
39     HEX_TWO_FLG = 0x2,
40     HEX_THREE_FLG = 0x3,
41     HEX_FOUR_FLG = 0x4,
42     HEX_FIVE_FLG = 0x5,
43     HEX_SIX_FLG = 0x6,
44     HEX_SEVEN_FLG = 0x7,
45     HEX_EIGHT_FLG = 0x8,
46     HEX_NINE_FLG = 0x9,
47     HEX_TEN_FLG = 0xA,
48     HEX_ELEVEN_FLG = 0xB,
49     HEX_TWELVE_FLG = 0xC,
50     HEX_THIRTEEN_FLG = 0xD,
51     HEX_FOURTEEN_FLG = 0xE,
52     HEX_FIFTEEN_FLG = 0xF,
53     HEX_SIXTEEN_FLG = 0X10,
54     MAX_CACHE_MASK = 128,
55 };
56 
57 napi_value DoParseUUID(napi_env env, napi_value src);
58 napi_value GetBinaryUUID(napi_env env, bool entropyCache);
59 std::string GetStringUUID(napi_env env, bool entropyCache);
60 bool GenerateUuid(unsigned char *data, int32_t size);
61 bool GetUUID(napi_env env, bool entropyCache, UUID &uuid);
62 std::string GetFormatUUID(const UUID &uuid);
63 unsigned char CharToHex(char in);
64 unsigned char ConvertBits(std::string &input);
65 unsigned char HexToChar(unsigned char _in);
66 }
67 #endif // UTIL_JS_UUID_H_