Debian Codegraph @

addons/auth_passkey/_vendor/webauthn/helpers/aaguid_to_string.py

raw
1 import codecs
2
3
4 def aaguid_to_string(val: bytes) -> str:
5 """
6 Take aaguid bytes and convert them to a GUID string
7 """
8 if len(val) != 16:
9 raise ValueError(f"AAGUID was {len(val)} bytes, expected 16 bytes")
10
11 # Convert to a hexadecimal string representation
12 to_hex = codecs.encode(val, encoding="hex").decode("utf-8")
13
14 # Split up the hex string into segments
15 # 8 chars
16 seg_1 = to_hex[0:8]
17 # 4 chars
18 seg_2 = to_hex[8:12]
19 # 4 chars
20 seg_3 = to_hex[12:16]
21 # 4 chars
22 seg_4 = to_hex[16:20]
23 # 12 chars
24 seg_5 = to_hex[20:32]
25
26 # "00000000-0000-0000-0000-000000000000"
27 return f"{seg_1}-{seg_2}-{seg_3}-{seg_4}-{seg_5}"