File tree Expand file tree Collapse file tree 2 files changed +16
-14
lines changed Expand file tree Collapse file tree 2 files changed +16
-14
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ Given a version number MAJOR.MINOR.PATCH, increment:
13
13
14
14
15
15
## [ Unreleased]
16
+ ### Fixed
17
+ - OID integer encoding when single number has more than 2 bytes
16
18
17
19
## [ 2.0.2] - 2021-11-09
18
20
### Fixed
Original file line number Diff line number Diff line change @@ -10,26 +10,26 @@ def oidFromHex(hexadecimal):
10
10
byte , remainingBytes = remainingBytes [0 :2 ], remainingBytes [2 :]
11
11
byteInt = intFromHex (byte )
12
12
if byteInt >= 128 :
13
- oidInt = byteInt - 128
13
+ oidInt = ( 128 * oidInt ) + ( byteInt - 128 )
14
14
continue
15
- oidInt = oidInt * 128 + byteInt
15
+ oidInt = ( 128 * oidInt ) + byteInt
16
16
oid .append (oidInt )
17
17
oidInt = 0
18
18
return oid
19
19
20
20
21
21
def oidToHex (oid ):
22
22
hexadecimal = hexFromInt (40 * oid [0 ] + oid [1 ])
23
- byteArray = []
24
- for oidInt in oid [2 :]:
25
- endDelta = 0
26
- while True :
27
- byteInt = oidInt % 128 + endDelta
28
- oidInt = oidInt // 128
29
- endDelta = 128
30
- byteArray .append (byteInt )
31
- if oidInt == 0 :
32
- break
33
- hexadecimal += "" .join (hexFromInt (byteInt ).zfill (2 ) for byteInt in reversed (byteArray ))
34
- byteArray = []
23
+ for number in oid [2 :]:
24
+ hexadecimal += _oidNumberToHex (number )
35
25
return hexadecimal
26
+
27
+
28
+ def _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"
You can’t perform that action at this time.
0 commit comments