Class: PacketGen::Header::ASN1Base Abstract
- Inherits:
-
RASN1::Model
- Object
- RASN1::Model
- PacketGen::Header::ASN1Base
- Includes:
- PacketGen::Headerable
- Defined in:
- lib/packetgen/header/asn1_base.rb
Overview
Direct Known Subclasses
Class Method Summary collapse
-
.define_attributes(*attributes) ⇒ void
Define some methods from given ASN.1 fields to mimic Base attributes.
- .known_headers ⇒ Object
Instance Method Summary collapse
-
#inspect ⇒ String
Common inspect method for ASN.1 headers.
-
#read(str) ⇒ ASN1Base
Read a BER string.
Methods included from PacketGen::Headerable
#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name
Class Method Details
.define_attributes(*attributes) ⇒ void
This method returns an undefined value.
Define some methods from given ASN.1 fields to mimic Base attributes
27 28 29 30 31 32 33 |
# File 'lib/packetgen/header/asn1_base.rb', line 27 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 ⇒ Object
35 36 37 |
# File 'lib/packetgen/header/asn1_base.rb', line 35 def known_headers @known_headers ||= {}.freeze end |
Instance Method Details
#inspect ⇒ String
Common inspect method for ASN.1 headers
57 58 59 60 61 62 63 |
# File 'lib/packetgen/header/asn1_base.rb', line 57 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) ⇒ ASN1Base
Read a BER string
46 47 48 49 50 51 52 53 |
# File 'lib/packetgen/header/asn1_base.rb', line 46 def read(str) begin parse(str, ber: true) rescue RASN1::ASN1Error # suppress exception to allow guessing end self end |