Class: PacketGen::Header::IKE::Attribute

Inherits:
Types::Fields show all
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).

Author:

  • Sylvain Daubert

Since:

  • 2.0.0

Constant Summary collapse

TYPE_KEY_LENGTH =

Since:

  • 2.0.0

14

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Since:

  • 2.0.0



41
42
43
44
45
46
47
48
# File 'lib/packetgen/header/ike/sa.rb', line 41

def initialize(options={})
  super
  if tv_format?
    self[:length].value = (options[:value] & 0xffff)
  else
    self[:length].value = 8 unless options[:length]
  end
end

Instance Attribute Details

#lengthInteger

Returns:

  • (Integer)

Since:

  • 2.0.0



35
# File 'lib/packetgen/header/ike/sa.rb', line 35

define_field :length, Types::Int16

#typeInteger

attribute type

Returns:

  • (Integer)


31
# File 'lib/packetgen/header/ike/sa.rb', line 31

define_field :type, Types::Int16

#valueInteger

Returns:

  • (Integer)

Since:

  • 2.0.0



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

Parameters:

  • str (String)

Returns:

  • (self)

Since:

  • 2.0.0



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_humanString

Get a human readable string

Returns:

  • (String)

Since:

  • 2.0.0



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_sString

Get binary string

Returns:

  • (String)

Since:

  • 2.0.0



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)

Returns:

  • (Boolean)

Since:

  • 2.0.0



91
92
93
# File 'lib/packetgen/header/ike/sa.rb', line 91

def tv_format?
  type & 0x8000 == 0x8000
end