Skip to content

Commit 0c7f99c

Browse files
ringaboutcapocasa
authored andcommitted
oids sticks to 24 length strings; fixes breaking changes (nim-lang#20546)
oids sticks 24 length strings
1 parent e824066 commit 0c7f99c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

lib/pure/oids.nim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ proc hexbyte*(hex: char): int {.inline.} =
4141

4242
proc parseOid*(str: cstring): Oid =
4343
## Parses an OID.
44-
var bytes = cast[cstring](addr(result.time))
44+
var bytes = cast[cstring](cast[pointer](cast[ByteAddress](addr(result.time)) + 4))
4545
var i = 0
46-
while i < 16:
46+
while i < 12:
4747
bytes[i] = chr((hexbyte(str[2 * i]) shl 4) or hexbyte(str[2 * i + 1]))
4848
inc(i)
4949

5050
proc `$`*(oid: Oid): string =
5151
## Converts an OID to a string.
5252
const hex = "0123456789abcdef"
5353

54-
result.setLen 32
54+
result.setLen 24
5555

5656
var o = oid
57-
var bytes = cast[cstring](addr(o))
57+
var bytes = cast[cstring](cast[pointer](cast[ByteAddress](addr(o)) + 4))
5858
var i = 0
59-
while i < 16:
59+
while i < 12:
6060
let b = bytes[i].ord
6161
result[2 * i] = hex[(b and 0xF0) shr 4]
6262
result[2 * i + 1] = hex[b and 0xF]
@@ -83,9 +83,9 @@ template genOid(result: var Oid, incr: var int, fuzz: int32) =
8383
proc genOid*(): Oid =
8484
## Generates a new OID.
8585
runnableExamples:
86-
doAssert ($genOid()).len == 32
86+
doAssert ($genOid()).len == 24
8787
runnableExamples("-r:off"):
88-
echo $genOid() # for example, "00000000632c452db08c3d19ee9073e5"
88+
echo $genOid() # for example, "5fc7f546ddbbc84800006aaf"
8989
genOid(result, incr, fuzz)
9090

9191
proc generatedTime*(oid: Oid): Time =

tests/stdlib/toids.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import std/assertions
77

88
block: # genOid
99
let x = genOid()
10-
doAssert ($x).len == 32
10+
doAssert ($x).len == 24
1111

1212
block:
1313
let x = genOid()

0 commit comments

Comments
 (0)