Class: PacketGen::Header::IKE::Transform
- Inherits:
-
Types::Fields
- Object
- Types::Fields
- PacketGen::Header::IKE::Transform
- Defined in:
- lib/packetgen/header/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::Header::IKE::Transform.new(type: 'ENCR', id: 'AES_CBC')
# using integer values
trans = PacketGen::Header::IKE::Transform.new(type: 1, id: 12)
Add attributes to a transform
# using an Attribute object
attr = PacketGen::Header::IKE::Attribute.new(type: 14, value: 128)
trans.attributes << attr
# using a hash
trans.attributes << { type: 14, value: 128 }
Constant Summary collapse
- TYPE_ENCR =
1- TYPE_PRF =
2- TYPE_INTG =
3- TYPE_DH =
4- TYPE_ESN =
5- 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 proposal length.
-
#rsv1 ⇒ Integer
8-bit reserved field.
-
#rsv2 ⇒ Integer
8-bit reserved field.
-
#type ⇒ Integer
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).
-
#read(str) ⇒ self
Populate object from a string.
-
#to_human ⇒ String
Get a human readable string.
Methods inherited from Types::Fields
#[], #[]=, #body=, define_bit_fields_on, define_field, define_field_after, define_field_before, delete_field, #fields, #force_binary, inherited, #inspect, #is_optional?, #is_present?, #optional_fields, #sz, #to_h, #to_s
Constructor Details
#initialize(options = {}) ⇒ Transform
Returns a new instance of Transform.
233 234 235 236 237 238 |
# File 'lib/packetgen/header/ike/sa.rb', line 233 def initialize(={}) super self[:length].value = sz unless [:length] self.type = [:type] if [:type] self.id = [:id] if [:id] end |
Instance Attribute Details
#attributes ⇒ Attributes
Set of attributes for this transform
231 |
# File 'lib/packetgen/header/ike/sa.rb', line 231 define_field :attributes, Attributes |
#id ⇒ Integer
16-bit transform ID. The Transform ID is the specific instance of the proposed transform type.
227 |
# File 'lib/packetgen/header/ike/sa.rb', line 227 define_field :id, 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.
205 |
# File 'lib/packetgen/header/ike/sa.rb', line 205 define_field :last, Types::Int8 |
#length ⇒ Integer
16-bit proposal length
213 |
# File 'lib/packetgen/header/ike/sa.rb', line 213 define_field :length, Types::Int16 |
#rsv1 ⇒ Integer
8-bit reserved field
209 |
# File 'lib/packetgen/header/ike/sa.rb', line 209 define_field :rsv1, Types::Int8 |
#rsv2 ⇒ Integer
8-bit reserved field
222 |
# File 'lib/packetgen/header/ike/sa.rb', line 222 define_field :rsv2, Types::Int8 |
#type ⇒ Integer
8-bit transform type. The Transform Type is the cryptographic algorithm type (i.e. encryption, PRF, integrity, etc.)
218 |
# File 'lib/packetgen/header/ike/sa.rb', line 218 define_field :type, Types::Int8 |
Instance Method Details
#calc_length ⇒ Integer
Compute length and set #length field
283 284 285 |
# File 'lib/packetgen/header/ike/sa.rb', line 283 def calc_length self[:length].value = sz end |
#human_id ⇒ String
Get human-readable ID
306 307 308 309 310 311 |
# File 'lib/packetgen/header/ike/sa.rb', line 306 def human_id name = self.class.constants.grep(/#{human_type}_/). select { |c| self.class.const_get(c) == id }. first || "ID=#{id}" name.to_s.sub(/#{human_type}_/, '') end |
#human_type ⇒ String
Get human-readable type
297 298 299 300 301 302 |
# File 'lib/packetgen/header/ike/sa.rb', line 297 def human_type name = self.class.constants.grep(/TYPE/). select { |c| self.class.const_get(c) == type }. first || "type[#{type}]" name.to_s.sub(/TYPE_/, '') end |
#last? ⇒ Boolean?
Say if this transform is the last one (from #last field)
315 316 317 318 319 320 321 322 323 324 |
# File 'lib/packetgen/header/ike/sa.rb', line 315 def last? case last when 0 true when 3 false else nil end end |
#read(str) ⇒ self
Populate object from a string
273 274 275 276 277 278 279 |
# File 'lib/packetgen/header/ike/sa.rb', line 273 def read(str) super hlen = self.class.new.sz attr_len = length - hlen attributes.read(str[hlen, attr_len]) self end |
#to_human ⇒ String
Get a human readable string
289 290 291 292 293 |
# File 'lib/packetgen/header/ike/sa.rb', line 289 def to_human h = "#{human_type}(#{human_id}" h << ",#{attributes.to_human}" if attributes.size > 0 h << ')' end |