Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/ellipticcurve/utils/oid.py: 11%
29 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1from .binary import intFromHex, hexFromInt
4def oidFromHex(hexadecimal):
5 firstByte, remainingBytes = hexadecimal[:2], hexadecimal[2:]
6 firstByteInt = intFromHex(firstByte)
7 oid = [firstByteInt // 40, firstByteInt % 40]
8 oidInt = 0
9 while len(remainingBytes) > 0:
10 byte, remainingBytes = remainingBytes[0:2], remainingBytes[2:]
11 byteInt = intFromHex(byte)
12 if byteInt >= 128:
13 oidInt = (128 * oidInt) + (byteInt - 128)
14 continue
15 oidInt = (128 * oidInt) + byteInt
16 oid.append(oidInt)
17 oidInt = 0
18 return oid
21def oidToHex(oid):
22 hexadecimal = hexFromInt(40 * oid[0] + oid[1])
23 for number in oid[2:]:
24 hexadecimal += _oidNumberToHex(number)
25 return hexadecimal
28def _oidNumberToHex(number):
29 hexadecimal = ""
30 endDelta = 0
31 while number > 0:
32 hexadecimal = hexFromInt((number % 128) + endDelta) + hexadecimal
33 number //= 128
34 endDelta = 128
35 return hexadecimal or "00"