xref: /aosp_15_r20/system/chre/chpp/tools/uuid_gen.py (revision 84e339476a462649f82315436d70fd732297a399)
1*84e33947SAndroid Build Coastguard Worker#!/usr/bin/python3
2*84e33947SAndroid Build Coastguard Worker#
3*84e33947SAndroid Build Coastguard Worker# Copyright (C) 2020 The Android Open Source Project
4*84e33947SAndroid Build Coastguard Worker#
5*84e33947SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*84e33947SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*84e33947SAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*84e33947SAndroid Build Coastguard Worker#
9*84e33947SAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
10*84e33947SAndroid Build Coastguard Worker#
11*84e33947SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*84e33947SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*84e33947SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*84e33947SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*84e33947SAndroid Build Coastguard Worker# limitations under the License.
16*84e33947SAndroid Build Coastguard Worker#
17*84e33947SAndroid Build Coastguard Worker
18*84e33947SAndroid Build Coastguard Worker#
19*84e33947SAndroid Build Coastguard Worker# This scripts prints a version 4 (random) UUID as a series of comma-separated
20*84e33947SAndroid Build Coastguard Worker# bytes in braces, so it can be easily used when developing a new CHPP client /
21*84e33947SAndroid Build Coastguard Worker# service.
22*84e33947SAndroid Build Coastguard Worker#
23*84e33947SAndroid Build Coastguard Worker
24*84e33947SAndroid Build Coastguard Workerimport uuid
25*84e33947SAndroid Build Coastguard Worker
26*84e33947SAndroid Build Coastguard Workeru = uuid.uuid4().hex
27*84e33947SAndroid Build Coastguard Workerprint("Generated version 4 (random) UUID is " + u)
28*84e33947SAndroid Build Coastguard Worker
29*84e33947SAndroid Build Coastguard Workerprint("{", end="")
30*84e33947SAndroid Build Coastguard Workerloc = 0
31*84e33947SAndroid Build Coastguard Workerwhile loc < len(u) - 2:  # loop through UUID bytes except last byte
32*84e33947SAndroid Build Coastguard Worker    print("0x" + u[loc:loc+2] + ", ", end="")
33*84e33947SAndroid Build Coastguard Worker    loc += 2
34*84e33947SAndroid Build Coastguard Workerprint("0x" + u[loc:loc+2] + "}")
35