class PacketGen::Header::ASN1Base
@abstract Base
class for ASN.1 header types.
This class implement minimal {Base} API to mimic a {Base} object. Subclasses may define magic methods: * {#parse?}.
@author Sylvain Daubert @since 2.0.0
Public Class Methods
define_attributes(*attributes)
click to toggle source
Define some methods from given ASN.1 fields to mimic {Base} attributes @param [Array<Symbol>] attributes @return [void]
# File lib/packetgen/header/asn1_base.rb, line 26 def define_attributes(*attributes) @attributes = attributes attributes.each do |attr| class_eval "def #{attr}; @elements[:#{attr}].value; end\n" \ "def #{attr}=(v); @elements[:#{attr}].value = v; end" end end
known_headers()
click to toggle source
# File lib/packetgen/header/asn1_base.rb, line 34 def known_headers @known_headers ||= {}.freeze end
Public Instance Methods
inspect()
click to toggle source
Common inspect method for ASN.1 headers @return [String]
# File lib/packetgen/header/asn1_base.rb, line 56 def inspect str = Inspect.dashed_line(self.class, 1) self.class.class_eval { @attributes }.each do |attr| str << Inspect.inspect_asn1_attribute(attr, self[attr], 1) end str end
read(str)
click to toggle source
Read a BER string @param [String] str @return [ASN1Base] self
# File lib/packetgen/header/asn1_base.rb, line 45 def read(str) begin parse(str, ber: true) rescue RASN1::ASN1Error # suppress exception to allow guessing end self end