Class: PacketGen::Header::ASN1Base Abstract
- Inherits:
-
RASN1::Model
- Object
- RASN1::Model
- PacketGen::Header::ASN1Base
- Defined in:
- lib/packetgen/header/asn1_base.rb
Overview
Base class for ASN.1 header types. Subclasses may define magic methods:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#packet ⇒ Object
private
Reference on packet which owns this header.
Class Method Summary collapse
-
.define_attributes(*attributes) ⇒ void
Define some methods from given ASN.1 fields to mimic Base attributes.
-
.protocol_name ⇒ String
Give protocol name for this class.
Instance Method Summary collapse
-
#inspect ⇒ String
Common inspect method for ASN.1 headers.
-
#method_name ⇒ String
return header method name.
- #parse? ⇒ true
-
#protocol_name ⇒ String
Return header protocol name.
-
#read(str) ⇒ ASN1Base
Read a BER string.
Instance Attribute Details
#packet ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reference on packet which owns this header
18 19 20 |
# File 'lib/packetgen/header/asn1_base.rb', line 18 def packet @packet end |
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
30 31 32 33 34 35 36 |
# File 'lib/packetgen/header/asn1_base.rb', line 30 def self.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 |
.protocol_name ⇒ String
Give protocol name for this class
23 24 25 |
# File 'lib/packetgen/header/asn1_base.rb', line 23 def self.protocol_name self.new.protocol_name end |
Instance Method Details
#inspect ⇒ String
Common inspect method for ASN.1 headers
77 78 79 80 81 82 83 |
# File 'lib/packetgen/header/asn1_base.rb', line 77 def inspect str = Inspect.dashed_line(self.class, 2) self.class.class_eval { @attributes }.each do |attr| str << Inspect.inspect_asn1_attribute(attr, self[attr], 2) end str end |
#method_name ⇒ String
return header method name
53 54 55 56 57 |
# File 'lib/packetgen/header/asn1_base.rb', line 53 def method_name return @method_name if @method_name @method_name = protocol_name.downcase.sub(/::/, '_') end |
#parse? ⇒ true
60 61 62 |
# File 'lib/packetgen/header/asn1_base.rb', line 60 def parse? true end |
#protocol_name ⇒ String
Return header protocol name
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/packetgen/header/asn1_base.rb', line 40 def protocol_name return @protocol_name if @protocol_name classname = self.class.to_s @protocol_name = if classname.start_with?('PacketGen::Header') classname.sub(/.*Header::/, '') else classname.sub(/.*::/, '') end end |
#read(str) ⇒ ASN1Base
Read a BER string
70 71 72 73 |
# File 'lib/packetgen/header/asn1_base.rb', line 70 def read(str) parse(str, ber: true) self end |