Skip to content

Commit 6f22cbd

Browse files
improve der internal method so that it deals with objects with no body
which means that it'll be nil; this improves encoding of asn1 nulls and cons with no elements
1 parent 725edfc commit 6f22cbd

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/openssl/asn1.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def cons_to_der
108108

109109
str = +""
110110

111-
@value.each_with_index do |item, idx|
111+
ary.each_with_index do |item, idx|
112112
if @indefinite_length && item.is_a?(EndOfContent)
113113
if idx != ary.size - 1
114114
raise ASN1Error, "illegal EOC octets in value"
@@ -131,7 +131,7 @@ def prim_to_der
131131

132132
def to_der_internal(body, constructed = false)
133133
default_tag = ASN1.take_default_tag(self.class)
134-
body_len = body.size
134+
body_len = body ? body.size : 0
135135

136136
if @tagging == :EXPLICIT
137137
raise ASN1Error, "explicit tagging of unknown tag" unless default_tag
@@ -144,13 +144,13 @@ def to_der_internal(body, constructed = false)
144144
# Put explicit tag
145145
str = ASN1.put_object(true, @indefinite_length, inner_len, @tag, @tag_class) << inner_obj
146146

147-
str << body
147+
str << body if body
148148
if @indefinite_length
149149
str << "\x00\x00\x00\x00"
150150
end
151151
else
152152
str = ASN1.put_object(constructed, @indefinite_length, body_len, @tag, @tag_class)
153-
str << body
153+
str << body if body
154154
if @indefinite_length
155155
str << "\x00\x00"
156156
end
@@ -250,7 +250,6 @@ def to_der
250250

251251
class Null < Primitive
252252
def der_value
253-
""
254253
end
255254
end
256255

0 commit comments

Comments
 (0)