Class: PacketGen::Plugin::IKE::Transform
- Inherits:
-
Types::Fields
- Object
- Types::Fields
- PacketGen::Plugin::IKE::Transform
- Defined in:
- lib/packetgen/plugin/ike/sa.rb
Overview
SA Tranform substructure, as defined in RFC 7296 §3.3.2
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Last Substruc | RESERVED | Transform Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Transform Type | RESERVED | Transform ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
~ Transform Attributes ~
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Create a Transform
# using type and id names
trans = PacketGen::Plugin::IKE::Transform.new(type: 'ENCR', id: 'AES_CBC')
# using integer values
trans = PacketGen::Plugin::IKE::Transform.new(type: 1, id: 12)
Add attributes to a transform
# using an Attribute object
attr = PacketGen::Plugin::IKE::Attribute.new(type: 14, value: 128)
trans.attributes << attr
# using a hash
trans.attributes << { type: 14, value: 128 }
Constant Summary collapse
- TYPES =
{ 'ENCR' => 1, 'PRF' => 2, 'INTG' => 3, 'DH' => 4, 'ESN' => 5 }.freeze
- ENCR_DES_IV64 =
1
- ENCR_DES =
2
- ENCR_3DES =
3
- ENCR_RC5 =
4
- ENCR_IDEA =
5
- ENCR_CAST =
6
- ENCR_BLOWFISH =
7
- ENCR_3IDEA =
8
- ENCR_DES_IV32 =
9
- ENCR_AES_CBC =
12
- ENCR_AES_CTR =
13
- ENCR_AES_CCM8 =
14
- ENCR_AES_CCM12 =
15
- ENCR_AES_CCM16 =
16
- ENCR_AES_GCM8 =
18
- ENCR_AES_GCM12 =
19
- ENCR_AES_GCM16 =
20
- ENCR_CAMELLIA_CBC =
23
- ENCR_CAMELLIA_CTR =
24
- ENCR_CAMELLIA_CCM8 =
25
- ENCR_CAMELLIA_CCM12 =
26
- ENCR_CAMELLIA_CCM16 =
27
- ENCR_CHACHA20_POLY1305 =
28
- PRF_HMAC_MD5 =
1
- PRF_HMAC_SHA1 =
2
- PRF_AES128_XCBC =
4
- PRF_HMAC_SHA2_256 =
5
- PRF_HMAC_SHA2_384 =
6
- PRF_HMAC_SHA2_512 =
7
- PRF_AES128_CMAC =
8
- INTG_NONE =
0
- INTG_HMAC_MD5_96 =
1
- INTG_HMAC_SHA1_96 =
2
- INTG_AES_XCBC_96 =
5
- INTG_HMAC_MD5_128 =
6
- INTG_HMAC_SHA1_160 =
7
- INTG_AES_CMAC_96 =
8
- INTG_AES128_GMAC =
9
- INTG_AES192_GMAC =
10
- INTG_AES256_GMAC =
11
- INTG_HMAC_SHA2_256_128 =
12
- INTG_HMAC_SHA2_384_192 =
13
- INTG_HMAC_SHA2_512_256 =
14
- DH_NONE =
0
- DH_MODP768 =
1
- DH_MODP1024 =
2
- DH_MODP1536 =
5
- DH_MODP2048 =
14
- DH_MODP3072 =
15
- DH_MODP4096 =
16
- DH_MODP6144 =
17
- DH_MODP8192 =
18
- DH_ECP256 =
19
- DH_ECP384 =
20
- DH_ECP521 =
21
- DH_BRAINPOOLP224 =
27
- DH_BRAINPOOLP256 =
28
- DH_BRAINPOOLP384 =
29
- DH_BRAINPOOLP512 =
30
- DH_CURVE25519 =
31
- DH_CURVE448 =
32
- ESN_NO_ESN =
0
- ESN_ESN =
1
Instance Attribute Summary collapse
-
#attributes ⇒ Attributes
Set of attributes for this transform.
-
#id ⇒ Integer
16-bit transform ID.
-
#last ⇒ Integer
8-bit last substructure.
-
#length ⇒ Integer
16-bit transform length.
-
#rsv1 ⇒ Integer
8-bit reserved field.
-
#rsv2 ⇒ Integer
8-bit reserved field.
-
#type ⇒ Integer
readonly
8-bit transform type.
Instance Method Summary collapse
-
#calc_length ⇒ Integer
Compute length and set #length field.
-
#human_id ⇒ String
Get human-readable ID.
-
#human_type ⇒ String
Get human-readable type.
-
#initialize(options = {}) ⇒ Transform
constructor
A new instance of Transform.
-
#last? ⇒ Boolean?
Say if this transform is the last one (from #last field).
-
#to_human ⇒ String
Get a human readable string.
Constructor Details
#initialize(options = {}) ⇒ Transform
Returns a new instance of Transform.
220 221 222 223 224 225 |
# File 'lib/packetgen/plugin/ike/sa.rb', line 220 def initialize(={}) super self.type = [:type] if [:type] self.id = [:id] if [:id] self[:length].value = sz unless [:length] end |
Instance Attribute Details
#attributes ⇒ Attributes
Set of attributes for this transform
218 |
# File 'lib/packetgen/plugin/ike/sa.rb', line 218 define_field :attributes, Attributes, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:attributes) }) } |
#id ⇒ Integer
16-bit transform ID. The Transform ID is the specific instance of the proposed transform type.
214 |
# File 'lib/packetgen/plugin/ike/sa.rb', line 214 define_field :id, PacketGen::Types::Int16 |
#last ⇒ Integer
8-bit last substructure. Specifies whether or not this is the last Transform Substructure in the Proposal. This field has a value of 0 if this was the last Transform Substructure, and a value of 3 if there are more Transform Substructures.
192 |
# File 'lib/packetgen/plugin/ike/sa.rb', line 192 define_field :last, PacketGen::Types::Int8 |
#length ⇒ Integer
16-bit transform length
200 |
# File 'lib/packetgen/plugin/ike/sa.rb', line 200 define_field :length, PacketGen::Types::Int16 |
#rsv1 ⇒ Integer
8-bit reserved field
196 |
# File 'lib/packetgen/plugin/ike/sa.rb', line 196 define_field :rsv1, PacketGen::Types::Int8 |
#rsv2 ⇒ Integer
8-bit reserved field
209 |
# File 'lib/packetgen/plugin/ike/sa.rb', line 209 define_field :rsv2, PacketGen::Types::Int8 |
Instance Method Details
#calc_length ⇒ Integer
Compute length and set #length field
246 247 248 |
# File 'lib/packetgen/plugin/ike/sa.rb', line 246 def calc_length PacketGen::Header::Base.calculate_and_set_length self end |
#human_id ⇒ String
Get human-readable ID
270 271 272 273 274 |
# File 'lib/packetgen/plugin/ike/sa.rb', line 270 def human_id name = self.class.constants.grep(/#{human_type}_/) .detect { |c| self.class.const_get(c) == id } || "ID=#{id}" name.to_s.sub(/#{human_type}_/, '') end |
#human_type ⇒ String
Get human-readable type
260 261 262 263 264 265 266 |
# File 'lib/packetgen/plugin/ike/sa.rb', line 260 def human_type if self[:type].enum.value? self.type self[:type].to_human else "type[#{self.type}]" end end |
#last? ⇒ Boolean?
Say if this transform is the last one (from #last field)
278 279 280 281 282 283 284 285 |
# File 'lib/packetgen/plugin/ike/sa.rb', line 278 def last? case last when 0 true when 3 false end end |
#to_human ⇒ String
Get a human readable string
252 253 254 255 256 |
# File 'lib/packetgen/plugin/ike/sa.rb', line 252 def to_human h = "#{human_type}(#{human_id}".dup h << ",#{attributes.to_human}" unless attributes.empty? h << ')' end |