• 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 #ifdef IOS_PLATFORM
25 #include <sys/sysctl.h>
26 #else
27 #include <sys/sysinfo.h>
28 #endif
29 #include <unistd.h>
30 
31 #include "napi/native_api.h"
32 #include "napi/native_node_api.h"
33 
34 namespace OHOS::Util {
35 constexpr const int UUID_SIZE = 16;
36 struct UUID {
37     unsigned char elements[16] = {0};
38 };
39 
40 enum ConvertFlags {
41     HEX_ZERO_FLG = 0x0,
42     HEX_ONE_FLG = 0x1,
43     HEX_TWO_FLG = 0x2,
44     HEX_THREE_FLG = 0x3,
45     HEX_FOUR_FLG = 0x4,
46     HEX_FIVE_FLG = 0x5,
47     HEX_SIX_FLG = 0x6,
48     HEX_SEVEN_FLG = 0x7,
49     HEX_EIGHT_FLG = 0x8,
50     HEX_NINE_FLG = 0x9,
51     HEX_TEN_FLG = 0xA,
52     HEX_ELEVEN_FLG = 0xB,
53     HEX_TWELVE_FLG = 0xC,
54     HEX_THIRTEEN_FLG = 0xD,
55     HEX_FOURTEEN_FLG = 0xE,
56     HEX_FIFTEEN_FLG = 0xF,
57     HEX_SIXTEEN_FLG = 0X10,
58     MAX_CACHE_MASK = 128,
59 };
60 
61 napi_value DoParseUUID(napi_env env, napi_value src);
62 napi_value GetBinaryUUID(napi_env env, bool entropyCache);
63 std::string GetStringUUID(napi_env env, bool entropyCache);
64 bool GenerateUuid(unsigned char *data, int32_t size);
65 bool GetUUID(napi_env env, bool entropyCache, UUID &uuid);
66 std::string GetFormatUUID(const UUID &uuid);
67 unsigned char CharToHex(char in);
68 unsigned char ConvertBits(std::string &input);
69 unsigned char HexToChar(unsigned char in);
70 }
71 #endif // UTIL_JS_UUID_H