summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-10-12 21:15:21 +0800
committerGitHub <noreply@github.com>2022-10-12 15:15:21 +0200
commit13b3ea71da8eecd4e8c61678ced3b19ef0625f6a (patch)
tree0d0f209aed1b8d5a5a48963ac13653597a289d33 /lib
parent7394587217c3ab26867d698b2ad89fb37cdcf3bb (diff)
downloadNim-13b3ea71da8eecd4e8c61678ced3b19ef0625f6a.tar.gz
oids sticks to 24 length strings; fixes breaking changes (#20546)
oids sticks 24 length strings
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/oids.nim14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/pure/oids.nim b/lib/pure/oids.nim
index 43eadad27..486e01ea3 100644
--- a/lib/pure/oids.nim
+++ b/lib/pure/oids.nim
@@ -41,9 +41,9 @@ proc hexbyte*(hex: char): int {.inline.} =
 
 proc parseOid*(str: cstring): Oid =
   ## Parses an OID.
-  var bytes = cast[cstring](addr(result.time))
+  var bytes = cast[cstring](cast[pointer](cast[ByteAddress](addr(result.time)) + 4))
   var i = 0
-  while i < 16:
+  while i < 12:
     bytes[i] = chr((hexbyte(str[2 * i]) shl 4) or hexbyte(str[2 * i + 1]))
     inc(i)
 
@@ -51,12 +51,12 @@ proc `$`*(oid: Oid): string =
   ## Converts an OID to a string.
   const hex = "0123456789abcdef"
 
-  result.setLen 32
+  result.setLen 24
 
   var o = oid
-  var bytes = cast[cstring](addr(o))
+  var bytes = cast[cstring](cast[pointer](cast[ByteAddress](addr(o)) + 4))
   var i = 0
-  while i < 16:
+  while i < 12:
     let b = bytes[i].ord
     result[2 * i] = hex[(b and 0xF0) shr 4]
     result[2 * i + 1] = hex[b and 0xF]
@@ -83,9 +83,9 @@ template genOid(result: var Oid, incr: var int, fuzz: int32) =
 proc genOid*(): Oid =
   ## Generates a new OID.
   runnableExamples:
-    doAssert ($genOid()).len == 32
+    doAssert ($genOid()).len == 24
   runnableExamples("-r:off"):
-    echo $genOid() # for example, "00000000632c452db08c3d19ee9073e5"
+    echo $genOid() # for example, "5fc7f546ddbbc84800006aaf"
   genOid(result, incr, fuzz)
 
 proc generatedTime*(oid: Oid): Time =