Skip to content

Commit fcb52d6

Browse files
committed
[sepc] Fix SA specs
Rename SA::Transform#attributes into #tattributes. Thus, this method no more clashes with BinStruct#attributes.
1 parent 2b45e34 commit fcb52d6

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

lib/packetgen/plugin/ike/sa.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ class Attributes < BinStruct::Array
102102
# == Add attributes to a transform
103103
# # using an Attribute object
104104
# attr = PacketGen::Plugin::IKE::Attribute.new(type: 14, value: 128)
105-
# trans.attributes << attr
105+
# trans.tattributes << attr
106106
# # using a hash
107-
# trans.attributes << { type: 14, value: 128 }
107+
# trans.tattributes << { type: 14, value: 128 }
108108
# @author Sylvain Daubert
109109
class Transform < BinStruct::Struct
110110
# Transform types
@@ -276,10 +276,10 @@ class Transform < BinStruct::Struct
276276
# the proposed transform type.
277277
# @return [Integer]
278278
define_attr :id, BinStruct::Int16
279-
# @!attribute attributes
279+
# @!attribute tattributes
280280
# Set of attributes for this transform
281281
# @return [Attributes]
282-
define_attr :attributes, Attributes, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:attributes) }) }
282+
define_attr :tattributes, Attributes, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:tattributes) }) }
283283

284284
def initialize(options={})
285285
super
@@ -316,7 +316,7 @@ def calc_length
316316
# @return [String]
317317
def to_human
318318
h = +"#{human_type}(#{human_id}"
319-
h << ",#{attributes.to_human}" unless attributes.empty?
319+
h << ",#{tattributes.to_human}" unless tattributes.empty?
320320

321321
h << ')'
322322
end
@@ -530,7 +530,7 @@ def push(prop)
530530
# # ID is taken from Transform::<TYPE>_* constants.
531531
# pkt.ike_sa.proposals.first.transforms << { type: 'ENCR', id: 'AES_CTR' }
532532
# # and finally, add an attribute to this transform (here, KEY_SIZE = 128 bits)
533-
# pkt.ike_sa.proposals[0].transforms[0].attributes << { type: 0x800e, value: 128 }
533+
# pkt.ike_sa.proposals[0].transforms[0].tattributes << { type: 0x800e, value: 128 }
534534
# pkt.calc_length
535535
# @author Sylvain Daubert
536536
class SA < Payload

spec/ike/sa_spec.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class IKE
106106
expect(trans.type).to eq(1)
107107
expect(trans.rsv2).to eq(0)
108108
expect(trans.id).to eq(0)
109-
expect(trans.attributes).to be_empty
109+
expect(trans.tattributes).to be_empty
110110
end
111111

112112
it 'accepts options' do
@@ -150,8 +150,8 @@ class IKE
150150
expect(@trans.rsv2).to eq(0)
151151
expect(@trans.id).to eq(20)
152152
expect(@trans.human_id).to eq('AES_GCM16')
153-
expect(@trans.attributes.size).to eq(1)
154-
expect(@trans.attributes.first.to_human).to eq('KEY_LENGTH=256')
153+
expect(@trans.tattributes.size).to eq(1)
154+
expect(@trans.tattributes.first.to_human).to eq('KEY_LENGTH=256')
155155
end
156156
end
157157

@@ -167,27 +167,27 @@ class IKE
167167
end
168168

169169
it 'returns a human readable string with undefined type and ID' do
170-
@trans[:type].read 50
170+
@trans[:type].value = 50
171171
@trans.id = 60
172-
@trans.attributes.clear
172+
@trans.tattributes.clear
173173
expect(@trans.to_human).to eq('type[50](ID=60)')
174174
end
175175

176-
describe '#attributes' do
176+
describe '#tattributes' do
177177
let (:trans) { Transform.new }
178178

179179
it 'accepts an Attribute' do
180180
attr = Attribute.new(type: 0x800e, value: 128)
181-
expect { trans.attributes << attr }.to change(trans.attributes, :size).by(1)
181+
expect { trans.tattributes << attr }.to change(trans.tattributes, :size).by(1)
182182
attr = Attribute.new(type: 12, value: 7)
183-
expect { trans.attributes << attr }.to change(trans.attributes, :size).by(1)
183+
expect { trans.tattributes << attr }.to change(trans.tattributes, :size).by(1)
184184
expect(trans.to_human).to eq('ENCR(ID=0,KEY_LENGTH=128,attr[12]=7)')
185185
end
186186

187187
it 'accepts a Hash describing an attribute' do
188-
expect { trans.attributes << { type: 0x800e, value: 192 } }.
189-
to change(trans.attributes, :size).by(1)
190-
expect(trans.attributes.first).to be_a(Attribute)
188+
expect { trans.tattributes << { type: 0x800e, value: 192 } }.
189+
to change(trans.tattributes, :size).by(1)
190+
expect(trans.tattributes.first).to be_a(Attribute)
191191
expect(trans.to_human).to eq('ENCR(ID=0,KEY_LENGTH=192)')
192192
end
193193
end
@@ -253,7 +253,7 @@ class IKE
253253
expect(@prop.human_protocol).to eq('ESP')
254254
expect(@prop.spi_size).to eq(4)
255255
expect(@prop.num_trans).to eq(2)
256-
expect(PacketGen::Types::Int32.new.read(@prop.spi).to_i).to eq(0x12345678)
256+
expect(BinStruct::Int32.new.read(@prop.spi).to_i).to eq(0x12345678)
257257
expect(@prop.transforms.size).to eq(2)
258258
expect(@prop.transforms.to_human).to eq('ENCR(DES_IV64),INTG(AES192_GMAC)')
259259
end
@@ -355,7 +355,7 @@ class IKE
355355
it 'returns a string with all attributes' do
356356
str = @sa.inspect
357357
expect(str).to be_a(String)
358-
(@sa.fields - %i(body)).each do |attr|
358+
(@sa.attributes - %i(body)).each do |attr|
359359
expect(str).to include(attr.to_s)
360360
end
361361
end
@@ -392,7 +392,7 @@ class IKE
392392
it 'sets length fields recursively' do
393393
@sa.proposals << { num: 2, protocol: 'IKE', last: 43 }
394394
@sa.proposals.last.transforms << { type: 'ENCR', id: 'AES_CTR' }
395-
@sa.proposals.last.transforms.last.attributes << { type: 0x800e, value: 128 }
395+
@sa.proposals.last.transforms.last.tattributes << { type: 0x800e, value: 128 }
396396
expect(@sa.proposals.last.length).to eq(8)
397397
expect(@sa.proposals.last.transforms.last.length).to eq(8)
398398
@sa.calc_length

0 commit comments

Comments
 (0)