Skip to content

Commit 4b110ff

Browse files
author
blackhedd
committed
Added String#read_ber!
1 parent 4db9f2c commit 4b110ff

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/net/ber.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,23 @@ class OpenSSL::SSL::SSLSocket
277277
# IO so we'd pick it up above. But you'd be wrong.
278278
end
279279

280-
class String
281-
def read_ber syntax=nil
282-
StringIO.new(self).read_ber(syntax)
283-
end
284-
end
285280

286281

282+
class String
283+
include Net::BER::BERParser
284+
def read_ber syntax=nil
285+
StringIO.new(self).read_ber(syntax)
286+
end
287+
def read_ber! syntax=nil
288+
obj,n_consumed = read_ber_from_string(self, syntax)
289+
if n_consumed
290+
self.slice!(0...n_consumed)
291+
obj
292+
else
293+
nil
294+
end
295+
end
296+
end
287297

288298
#----------------------------------------------
289299

0 commit comments

Comments
 (0)