Skip to content

Commit 6860965

Browse files
author
blackhedd
committed
supported translation of the X.690 OID representation.
More useful for SNMP than for LDAP.
1 parent 8dfbf21 commit 6860965

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/net/ber.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module BERParser
8888
2 => :integer,
8989
4 => :string,
9090
5 => :null,
91-
6 => :string, # (OID)
91+
6 => :oid,
9292
10 => :integer,
9393
13 => :string # (relative OID)
9494
},
@@ -147,6 +147,23 @@ def read_ber syntax=nil
147147
j = 0
148148
newobj.each_byte {|b| j = (j << 8) + b}
149149
j
150+
elsif objtype == :oid
151+
# cf X.690 pgh 8.19 for an explanation of this algorithm.
152+
# Potentially not good enough. We may need a BerIdentifiedOid
153+
# as a subclass of BerIdentifiedArray, to get the ber identifier
154+
# and also a to_s method that produces the familiar dotted notation.
155+
oid = newobj.unpack("w*")
156+
f = oid.shift
157+
g = if f < 40
158+
[0, f]
159+
elsif f < 80
160+
[1, f-40]
161+
else
162+
[2, f-80] # f-80 can easily be > 80. What a weird optimization.
163+
end
164+
oid.unshift g.last
165+
oid.unshift g.first
166+
oid
150167
elsif objtype == :array
151168
#seq = []
152169
seq = BerIdentifiedArray.new

0 commit comments

Comments
 (0)