Class: PacketGen::Header::IKE::Attribute
- Inherits:
-
Types::Fields
- Object
- Types::Fields
- PacketGen::Header::IKE::Attribute
- Defined in:
- lib/packetgen/header/ike/sa.rb
Overview
Transform attribute.
1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|A| Attribute Type | AF=0 Attribute Length |
|F| | AF=1 Attribute Value |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| AF=0 Attribute Value |
| AF=1 Not Transmitted |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Such an attribute may have a TLV (Type/length/value) format if AF=0, or a TV format (AF=1).
Constant Summary collapse
- TYPE_KEY_LENGTH =
14
Instance Attribute Summary collapse
- #length ⇒ Integer
-
#type ⇒ Integer
attribute type.
- #value ⇒ Integer
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
-
#read(str) ⇒ self
Populate object from a string.
-
#to_human ⇒ String
Get a human readable string.
-
#to_s ⇒ String
Get binary string.
-
#tv_format? ⇒ Boolean
Say if attribute use TV format (
true) or TLV one (false).
Methods inherited from Types::Fields
#[], #[]=, #bits_on, #body=, define_bit_fields_on, define_field, define_field_after, define_field_before, delete_field, fields, #fields, #force_binary, inherited, #inspect, #is_optional?, #is_present?, #offset_of, #optional?, #optional_fields, #present?, remove_bit_fields_on, remove_field, #sz, #to_h, update_field
Constructor Details
#initialize(options = {}) ⇒ Attribute
Returns a new instance of Attribute.
41 42 43 44 45 46 47 48 |
# File 'lib/packetgen/header/ike/sa.rb', line 41 def initialize(={}) super if tv_format? self[:length].value = ([:value] & 0xffff) else self[:length].value = 8 unless [:length] end end |
Instance Attribute Details
#length ⇒ Integer
35 |
# File 'lib/packetgen/header/ike/sa.rb', line 35 define_field :length, Types::Int16 |
#type ⇒ Integer
attribute type
31 |
# File 'lib/packetgen/header/ike/sa.rb', line 31 define_field :type, Types::Int16 |
#value ⇒ Integer
39 |
# File 'lib/packetgen/header/ike/sa.rb', line 39 define_field :value, Types::Int32 |
Instance Method Details
#read(str) ⇒ self
Populate object from a string
63 64 65 66 67 68 69 70 |
# File 'lib/packetgen/header/ike/sa.rb', line 63 def read(str) return self if str.nil? force_binary str self[:type].read str[0, 2] self[:length].read str[2, 2] self[:value].read str[4, 4] unless tv_format? self end |
#to_human ⇒ String
Get a human readable string
82 83 84 85 86 87 |
# File 'lib/packetgen/header/ike/sa.rb', line 82 def to_human name = self.class.constants.grep(/TYPE_/) .detect { |c| self.class.const_get(c) == (type & 0x7fff) } || "attr[#{type & 0x7fff}]" name = name.to_s.sub(/TYPE_/, '') "#{name}=#{value}" end |
#to_s ⇒ String
Get binary string
74 75 76 77 78 |
# File 'lib/packetgen/header/ike/sa.rb', line 74 def to_s str = self[:type].to_s + self[:length].to_s str << self[:value].to_s unless tv_format? str end |
#tv_format? ⇒ Boolean
Say if attribute use TV format (true) or TLV one (false)
91 92 93 |
# File 'lib/packetgen/header/ike/sa.rb', line 91 def tv_format? type & 0x8000 == 0x8000 end |