Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

OpenSSL::ASN1.traverse

OpenSSL::ASN1.traverse(asn1) → nil

If a block is given, it prints out each of the elements encountered. Block parameters are (in that order):

  • depth: The recursion depth, plus one with each constructed value being encountered (Integer)

  • offset: Current byte offset (Integer)

  • header length: Combined length in bytes of the Tag and Length headers. (Integer)

  • length: The overall remaining length of the entire data (Integer)

  • constructed: Whether this value is constructed or not (Boolean)

  • tag_class: Current tag class (Symbol)

  • tag: The current tag number (Integer)

Example

Example
der = File.binread('asn1data.der')
OpenSSL::ASN1.traverse(der) do | depth, offset, header_len, length, constructed, tag_class, tag|
  puts "Depth: #{depth} Offset: #{offset} Length: #{length}"
  puts "Header length: #{header_len} Tag: #{tag} Tag class: #{tag_class} Constructed: #{constructed}"
end
See also .decode_all .decode also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0