Class: PacketGen::Header::ASN1Base Abstract
- Inherits:
-
RASN1::Model
- Object
- RASN1::Model
- PacketGen::Header::ASN1Base
- Defined in:
- lib/packetgen/header/asn1_base.rb
Overview
Direct Known Subclasses
Instance Attribute Summary collapse
-
#packet ⇒ Packet?
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
- #added_to_packet(packet) ⇒ void abstract
-
#inspect ⇒ String
Common inspect method for ASN.1 headers.
-
#method_name ⇒ String
return header method name.
-
#parse? ⇒ true
Called by Packet#parse when guessing first header to check if header is correct.
-
#protocol_name ⇒ String
Return header protocol name.
-
#read(str) ⇒ ASN1Base
Read a BER string.
Instance Attribute Details
#packet ⇒ Packet?
Reference on packet which owns this header
22 23 24 |
# File 'lib/packetgen/header/asn1_base.rb', line 22 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
34 35 36 37 38 39 40 |
# File 'lib/packetgen/header/asn1_base.rb', line 34 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
27 28 29 |
# File 'lib/packetgen/header/asn1_base.rb', line 27 def self.protocol_name self.new.protocol_name end |
Instance Method Details
#added_to_packet(packet) ⇒ void
This method is called when a header is added to a packet. This base method does nothing but may be overriden by subclasses.
This method returns an undefined value.
87 |
# File 'lib/packetgen/header/asn1_base.rb', line 87 def added_to_packet(packet) end |
#inspect ⇒ String
Common inspect method for ASN.1 headers
102 103 104 105 106 107 108 |
# File 'lib/packetgen/header/asn1_base.rb', line 102 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 |
#method_name ⇒ String
return header method name
58 59 60 61 62 |
# File 'lib/packetgen/header/asn1_base.rb', line 58 def method_name return @method_name if @method_name @method_name = protocol_name.downcase.sub(/::/, '_') end |
#parse? ⇒ true
Called by Packet#parse when guessing first header to check if header is correct
67 68 69 |
# File 'lib/packetgen/header/asn1_base.rb', line 67 def parse? true end |
#protocol_name ⇒ String
Return header protocol name
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/packetgen/header/asn1_base.rb', line 44 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
95 96 97 98 |
# File 'lib/packetgen/header/asn1_base.rb', line 95 def read(str) parse(str, ber: true) self end |