Skip to content

Commit 1d1a1a6

Browse files
author
blackhedd
committed
DRY violated
1 parent 6860965 commit 1d1a1a6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/net/ber.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,23 @@ def read_ber_from_string str, syntax=nil
252252
j = 0
253253
newobj.each_byte {|b| j = (j << 8) + b}
254254
j
255+
elsif objtype == :oid
256+
# cf X.690 pgh 8.19 for an explanation of this algorithm.
257+
# Potentially not good enough. We may need a BerIdentifiedOid
258+
# as a subclass of BerIdentifiedArray, to get the ber identifier
259+
# and also a to_s method that produces the familiar dotted notation.
260+
oid = newobj.unpack("w*")
261+
f = oid.shift
262+
g = if f < 40
263+
[0,f]
264+
elsif f < 80
265+
[1, f-40]
266+
else
267+
[2, f-80] # f-80 can easily be > 80. What a weird optimization.
268+
end
269+
oid.unshift g.last
270+
oid.unshift g.first
271+
oid
255272
elsif objtype == :boolean
256273
newobj != "\000"
257274
elsif objtype == :null

0 commit comments

Comments
 (0)