packetfu 1.1.10 → 1.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -0
  4. data/.gitignore +3 -0
  5. data/.travis.yml +8 -0
  6. data/CONTRIBUTING.md +47 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +1 -1
  9. data/README.rdoc +35 -30
  10. data/Rakefile +4 -4
  11. data/bench/octets.rb +9 -9
  12. data/examples/100kpackets.rb +12 -12
  13. data/examples/ackscan.rb +16 -16
  14. data/examples/arp.rb +35 -35
  15. data/examples/arphood.rb +36 -36
  16. data/examples/dissect_thinger.rb +6 -6
  17. data/examples/new-simple-stats.rb +23 -23
  18. data/examples/packetfu-shell.rb +25 -25
  19. data/examples/simple-sniffer.rb +9 -9
  20. data/examples/simple-stats.rb +23 -23
  21. data/examples/slammer.rb +3 -3
  22. data/gem-public_cert.pem +21 -0
  23. data/lib/packetfu.rb +149 -127
  24. data/lib/packetfu/capture.rb +169 -169
  25. data/lib/packetfu/config.rb +52 -52
  26. data/lib/packetfu/inject.rb +56 -56
  27. data/lib/packetfu/packet.rb +531 -528
  28. data/lib/packetfu/pcap.rb +579 -579
  29. data/lib/packetfu/protos/arp.rb +90 -90
  30. data/lib/packetfu/protos/arp/header.rb +158 -158
  31. data/lib/packetfu/protos/arp/mixin.rb +36 -36
  32. data/lib/packetfu/protos/eth.rb +44 -44
  33. data/lib/packetfu/protos/eth/header.rb +243 -243
  34. data/lib/packetfu/protos/eth/mixin.rb +3 -3
  35. data/lib/packetfu/protos/hsrp.rb +69 -69
  36. data/lib/packetfu/protos/hsrp/header.rb +107 -107
  37. data/lib/packetfu/protos/hsrp/mixin.rb +29 -29
  38. data/lib/packetfu/protos/icmp.rb +71 -71
  39. data/lib/packetfu/protos/icmp/header.rb +82 -82
  40. data/lib/packetfu/protos/icmp/mixin.rb +14 -14
  41. data/lib/packetfu/protos/invalid.rb +49 -49
  42. data/lib/packetfu/protos/ip.rb +69 -69
  43. data/lib/packetfu/protos/ip/header.rb +291 -291
  44. data/lib/packetfu/protos/ip/mixin.rb +40 -40
  45. data/lib/packetfu/protos/ipv6.rb +50 -50
  46. data/lib/packetfu/protos/ipv6/header.rb +188 -188
  47. data/lib/packetfu/protos/ipv6/mixin.rb +29 -29
  48. data/lib/packetfu/protos/tcp.rb +176 -176
  49. data/lib/packetfu/protos/tcp/ecn.rb +35 -35
  50. data/lib/packetfu/protos/tcp/flags.rb +74 -74
  51. data/lib/packetfu/protos/tcp/header.rb +268 -268
  52. data/lib/packetfu/protos/tcp/hlen.rb +32 -32
  53. data/lib/packetfu/protos/tcp/mixin.rb +46 -46
  54. data/lib/packetfu/protos/tcp/option.rb +321 -321
  55. data/lib/packetfu/protos/tcp/options.rb +95 -95
  56. data/lib/packetfu/protos/tcp/reserved.rb +35 -35
  57. data/lib/packetfu/protos/udp.rb +159 -123
  58. data/lib/packetfu/protos/udp/header.rb +91 -91
  59. data/lib/packetfu/protos/udp/mixin.rb +3 -3
  60. data/lib/packetfu/structfu.rb +280 -280
  61. data/lib/packetfu/utils.rb +292 -225
  62. data/lib/packetfu/version.rb +41 -41
  63. data/packetfu.gemspec +14 -3
  64. data/spec/arp_spec.rb +191 -0
  65. data/spec/eth_spec.rb +148 -0
  66. data/spec/icmp_spec.rb +97 -0
  67. data/spec/ip_spec.rb +78 -0
  68. data/spec/ipv6_spec.rb +81 -0
  69. data/spec/packet_spec.rb +61 -59
  70. data/spec/packet_subclasses_spec.rb +9 -10
  71. data/spec/packetfu_spec.rb +55 -62
  72. data/spec/sample3.pcap +0 -0
  73. data/spec/spec_helper.rb +44 -0
  74. data/spec/structfu_spec.rb +270 -271
  75. data/spec/tcp_spec.rb +76 -77
  76. data/spec/udp_spec.rb +32 -0
  77. data/spec/utils_spec.rb +95 -0
  78. data/test/all_tests.rb +14 -17
  79. data/test/func_lldp.rb +3 -3
  80. data/test/ptest.rb +2 -2
  81. data/test/test_capture.rb +45 -45
  82. data/test/test_eth.rb +70 -68
  83. data/test/test_hsrp.rb +9 -9
  84. data/test/test_inject.rb +18 -18
  85. data/test/test_invalid.rb +16 -16
  86. data/test/test_octets.rb +23 -21
  87. data/test/test_packet.rb +156 -154
  88. data/test/test_pcap.rb +172 -170
  89. data/test/test_structfu.rb +99 -97
  90. data/test/test_tcp.rb +322 -320
  91. data/test/test_udp.rb +78 -76
  92. metadata +108 -44
  93. metadata.gz.sig +2 -0
  94. data/spec/ethpacket_spec.rb +0 -74
  95. data/test/test_arp.rb +0 -135
  96. data/test/test_icmp.rb +0 -62
  97. data/test/test_ip.rb +0 -50
  98. data/test/test_ip6.rb +0 -68
Binary file
@@ -0,0 +1,44 @@
1
+
2
+ $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib")
3
+ require 'packetfu'
4
+
5
+ puts "rspec #{RSpec::Core::Version::STRING}"
6
+ if RSpec::Core::Version::STRING[0] == '3'
7
+ require 'rspec/its'
8
+ RSpec.configure do |config|
9
+ #config.raise_errors_for_deprecations!
10
+ config.expect_with :rspec do |c|
11
+ c.syntax = [:expect, :should]
12
+ end
13
+ end
14
+ end
15
+
16
+
17
+ module FakePacket
18
+ def layer
19
+ 7
20
+ end
21
+ end
22
+
23
+ class PacketFu::FooPacket < PacketFu::Packet
24
+ extend FakePacket
25
+ end
26
+
27
+ class PacketFu::BarPacket < PacketFu::Packet
28
+ extend FakePacket
29
+ end
30
+
31
+ class PacketBaz
32
+ end
33
+
34
+ def add_fake_packets
35
+ PacketFu.add_packet_class(PacketFu::FooPacket)
36
+ PacketFu.add_packet_class(PacketFu::BarPacket)
37
+ end
38
+
39
+ def remove_fake_packets
40
+ PacketFu.remove_packet_class(PacketFu::FooPacket)
41
+ PacketFu.remove_packet_class(PacketFu::BarPacket)
42
+ end
43
+
44
+ remove_fake_packets
@@ -1,335 +1,334 @@
1
- $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib")
2
- require 'packetfu'
1
+ require 'spec_helper'
3
2
 
4
3
  describe StructFu, "mixin methods" do
5
4
 
6
- before :each do
7
- class StructClass
8
- include StructFu
9
- end
10
- @sc = StructClass.new
11
- end
12
-
13
- it "should provide the basic StructFu methods" do
14
- @sc.respond_to?(:sz).should be_true
15
- @sc.respond_to?(:len).should be_true
16
- @sc.respond_to?(:typecast).should be_true
17
- @sc.respond_to?(:body=).should be_true
18
- end
19
- end
5
+ before :each do
6
+ class StructClass
7
+ include StructFu
8
+ end
9
+ @sc = StructClass.new
10
+ end
11
+
12
+ it "should provide the basic StructFu methods" do
13
+ @sc.respond_to?(:sz).should be true
14
+ @sc.respond_to?(:len).should be true
15
+ @sc.respond_to?(:typecast).should be true
16
+ @sc.respond_to?(:body=).should be true
17
+ end
18
+ end
20
19
 
21
20
  describe StructFu::Int, "basic Int class" do
22
21
 
23
- before :each do
24
- @int = StructFu::Int.new(8)
25
- end
26
-
27
- it "should have an initial state" do
28
- new_int = StructFu::Int.new
29
- new_int.value.should be_nil
30
- new_int.endian.should be_nil
31
- new_int.width.should be_nil
32
- new_int.default.should == 0
33
- end
34
-
35
- it "should raise when to_s'ed directly" do
36
- expect { @int.to_s}.to raise_error
37
- end
38
-
39
- it "should have a value of 8" do
40
- @int.value.should == 8
41
- @int.to_i.should == 8
42
- @int.to_f.to_s.should == "8.0"
43
- end
44
-
45
- it "should read an integer" do
46
- @int.read(7)
47
- @int.to_i.should == 7
48
- end
22
+ before :each do
23
+ @int = StructFu::Int.new(8)
24
+ end
25
+
26
+ it "should have an initial state" do
27
+ new_int = StructFu::Int.new
28
+ new_int.value.should be_nil
29
+ new_int.endian.should be_nil
30
+ new_int.width.should be_nil
31
+ new_int.default.should == 0
32
+ end
33
+
34
+ it "should raise when to_s'ed directly" do
35
+ expect { @int.to_s}.to raise_error(StandardError, "StructFu::Int#to_s accessed, must be redefined.")
36
+ end
37
+
38
+ it "should have a value of 8" do
39
+ @int.value.should == 8
40
+ @int.to_i.should == 8
41
+ @int.to_f.to_s.should == "8.0"
42
+ end
43
+
44
+ it "should read an integer" do
45
+ @int.read(7)
46
+ @int.to_i.should == 7
47
+ end
49
48
 
50
49
  end
51
50
 
52
51
  describe StructFu::Int8, "one byte value" do
53
52
 
54
- before :each do
55
- @int = StructFu::Int8.new(11)
56
- end
57
-
58
- it "should have an initial state" do
59
- new_int = StructFu::Int8.new
60
- new_int.value.should be_nil
61
- new_int.endian.should be_nil
62
- new_int.width.should == 1
63
- new_int.default.should == 0
64
- end
65
-
66
- it "should print a one character packed string" do
67
- @int.to_s.should == "\x0b"
68
- end
69
-
70
- it "should have a value of 11" do
71
- @int.value.should == 11
72
- @int.to_i.should == 11
73
- @int.to_f.to_s.should == "11.0"
74
- end
75
-
76
- it "should reset with a new integer" do
77
- @int.read(2)
78
- @int.to_i.should == 2
79
- @int.to_s.should == "\x02"
80
- @int.read(254)
81
- @int.to_i.should == 254
82
- @int.to_s.should == "\xfe"
83
- end
53
+ before :each do
54
+ @int = StructFu::Int8.new(11)
55
+ end
56
+
57
+ it "should have an initial state" do
58
+ new_int = StructFu::Int8.new
59
+ new_int.value.should be_nil
60
+ new_int.endian.should be_nil
61
+ new_int.width.should == 1
62
+ new_int.default.should == 0
63
+ end
64
+
65
+ it "should print a one character packed string" do
66
+ @int.to_s.should == "\x0b"
67
+ end
68
+
69
+ it "should have a value of 11" do
70
+ @int.value.should == 11
71
+ @int.to_i.should == 11
72
+ @int.to_f.to_s.should == "11.0"
73
+ end
74
+
75
+ it "should reset with a new integer" do
76
+ @int.read(2)
77
+ @int.to_i.should == 2
78
+ @int.to_s.should == "\x02"
79
+ @int.read(254)
80
+ @int.to_i.should == 254
81
+ @int.to_s.should == "\xfe".force_encoding("binary")
82
+ end
84
83
 
85
84
  end
86
85
 
87
86
  describe StructFu::Int16, "two byte value" do
88
87
 
89
- before :each do
90
- @int = StructFu::Int16.new(11)
91
- end
92
-
93
- it "should have an initial state" do
94
- new_int = StructFu::Int16.new
95
- new_int.value.should be_nil
96
- new_int.endian.should == :big
97
- new_int.width.should == 2
98
- new_int.default.should == 0
99
- end
100
-
101
- it "should print a two character packed string" do
102
- @int.to_s.should == "\x00\x0b"
103
- end
104
-
105
- it "should have a value of 11" do
106
- @int.value.should == 11
107
- @int.to_i.should == 11
108
- @int.to_f.to_s.should == "11.0"
109
- end
110
-
111
- it "should reset with a new integer" do
112
- @int.read(2)
113
- @int.to_i.should == 2
114
- @int.to_s.should == "\x00\x02"
115
- @int.read(254)
116
- @int.to_i.should == 254
117
- @int.to_s.should == "\x00\xfe"
118
- end
119
-
120
- it "should be able to set endianness" do
121
- int_be = StructFu::Int16.new(11,:big)
122
- int_be.to_s.should == "\x00\x0b"
123
- int_le = StructFu::Int16.new(11,:little)
124
- int_le.to_s.should == "\x0b\x00"
125
- end
126
-
127
- it "should be able to switch endianness" do
128
- @int.endian.should == :big
129
- @int.to_s.should == "\x00\x0b"
130
- @int.endian = :little
131
- @int.endian.should == :little
132
- @int.read(11)
133
- @int.to_s.should == "\x0b\x00"
134
- end
88
+ before :each do
89
+ @int = StructFu::Int16.new(11)
90
+ end
91
+
92
+ it "should have an initial state" do
93
+ new_int = StructFu::Int16.new
94
+ new_int.value.should be_nil
95
+ new_int.endian.should == :big
96
+ new_int.width.should == 2
97
+ new_int.default.should == 0
98
+ end
99
+
100
+ it "should print a two character packed string" do
101
+ @int.to_s.should == "\x00\x0b".force_encoding("binary")
102
+ end
103
+
104
+ it "should have a value of 11" do
105
+ @int.value.should == 11
106
+ @int.to_i.should == 11
107
+ @int.to_f.to_s.should == "11.0"
108
+ end
109
+
110
+ it "should reset with a new integer" do
111
+ @int.read(2)
112
+ @int.to_i.should == 2
113
+ @int.to_s.should == "\x00\x02"
114
+ @int.read(254)
115
+ @int.to_i.should == 254
116
+ @int.to_s.should == "\x00\xfe".force_encoding("binary")
117
+ end
118
+
119
+ it "should be able to set endianness" do
120
+ int_be = StructFu::Int16.new(11,:big)
121
+ int_be.to_s.should == "\x00\x0b"
122
+ int_le = StructFu::Int16.new(11,:little)
123
+ int_le.to_s.should == "\x0b\x00"
124
+ end
125
+
126
+ it "should be able to switch endianness" do
127
+ @int.endian.should == :big
128
+ @int.to_s.should == "\x00\x0b"
129
+ @int.endian = :little
130
+ @int.endian.should == :little
131
+ @int.read(11)
132
+ @int.to_s.should == "\x0b\x00"
133
+ end
135
134
 
136
135
  end
137
136
 
138
137
  describe StructFu::Int16le, "2 byte little-endian value" do
139
138
 
140
- before :each do
141
- @int = StructFu::Int16le.new(11)
142
- end
139
+ before :each do
140
+ @int = StructFu::Int16le.new(11)
141
+ end
143
142
 
144
- it "should behave pretty much like any other 16 bit int" do
145
- @int.to_s.should == "\x0b\x00"
146
- end
143
+ it "should behave pretty much like any other 16 bit int" do
144
+ @int.to_s.should == "\x0b\x00"
145
+ end
147
146
 
148
- it "should raise when you try to change endianness" do
149
- expect { @int.endian = :big }.to raise_error
150
- expect { @int.endian = :little }.to raise_error
151
- end
147
+ it "should raise when you try to change endianness" do
148
+ expect { @int.endian = :big }.to raise_error(NoMethodError, /undefined method `endian='/)
149
+ expect { @int.endian = :little }.to raise_error(NoMethodError, /undefined method `endian='/)
150
+ end
152
151
 
153
152
  end
154
153
 
155
154
  describe StructFu::Int16be, "2 byte big-endian value" do
156
155
 
157
- before :each do
158
- @int = StructFu::Int16be.new(11)
159
- end
156
+ before :each do
157
+ @int = StructFu::Int16be.new(11)
158
+ end
160
159
 
161
- it "should behave pretty much like any other 16 bit int" do
162
- @int.to_s.should == "\x00\x0b"
163
- end
160
+ it "should behave pretty much like any other 16 bit int" do
161
+ @int.to_s.should == "\x00\x0b"
162
+ end
164
163
 
165
- it "should raise when you try to change endianness" do
166
- expect { @int.endian = :big }.to raise_error
167
- expect { @int.endian = :little }.to raise_error
168
- end
164
+ it "should raise when you try to change endianness" do
165
+ expect { @int.endian = :big }.to raise_error(NoMethodError, /undefined method `endian='/)
166
+ expect { @int.endian = :little }.to raise_error(NoMethodError, /undefined method `endian='/)
167
+ end
169
168
 
170
169
  end
171
170
 
172
171
  describe StructFu::Int32, "four byte value" do
173
172
 
174
- before :each do
175
- @int = StructFu::Int32.new(11)
176
- end
177
-
178
- it "should have an initial state" do
179
- new_int = StructFu::Int32.new
180
- new_int.value.should be_nil
181
- new_int.endian.should == :big
182
- new_int.width.should == 4
183
- new_int.default.should == 0
184
- end
185
-
186
- it "should print a four character packed string" do
187
- @int.to_s.should == "\x00\x00\x00\x0b"
188
- end
189
-
190
- it "should have a value of 11" do
191
- @int.value.should == 11
192
- @int.to_i.should == 11
193
- @int.to_f.to_s.should == "11.0"
194
- end
195
-
196
- it "should reset with a new integer" do
197
- @int.read(2)
198
- @int.to_i.should == 2
199
- @int.to_s.should == "\x00\x00\x00\x02"
200
- @int.read(254)
201
- @int.to_i.should == 254
202
- @int.to_s.should == "\x00\x00\x00\xfe"
203
- end
204
-
205
- it "should be able to set endianness" do
206
- int_be = StructFu::Int32.new(11,:big)
207
- int_be.to_s.should == "\x00\x00\x00\x0b"
208
- int_le = StructFu::Int32.new(11,:little)
209
- int_le.to_s.should == "\x0b\x00\x00\x00"
210
- end
211
-
212
- it "should be able to switch endianness" do
213
- @int.endian.should == :big
214
- @int.to_s.should == "\x00\x00\x00\x0b"
215
- @int.endian = :little
216
- @int.endian.should == :little
217
- @int.read(11)
218
- @int.to_s.should == "\x0b\x00\x00\x00"
219
- end
173
+ before :each do
174
+ @int = StructFu::Int32.new(11)
175
+ end
176
+
177
+ it "should have an initial state" do
178
+ new_int = StructFu::Int32.new
179
+ new_int.value.should be_nil
180
+ new_int.endian.should == :big
181
+ new_int.width.should == 4
182
+ new_int.default.should == 0
183
+ end
184
+
185
+ it "should print a four character packed string" do
186
+ @int.to_s.should == "\x00\x00\x00\x0b"
187
+ end
188
+
189
+ it "should have a value of 11" do
190
+ @int.value.should == 11
191
+ @int.to_i.should == 11
192
+ @int.to_f.to_s.should == "11.0"
193
+ end
194
+
195
+ it "should reset with a new integer" do
196
+ @int.read(2)
197
+ @int.to_i.should == 2
198
+ @int.to_s.should == "\x00\x00\x00\x02"
199
+ @int.read(254)
200
+ @int.to_i.should == 254
201
+ @int.to_s.should == "\x00\x00\x00\xfe".force_encoding("binary")
202
+ end
203
+
204
+ it "should be able to set endianness" do
205
+ int_be = StructFu::Int32.new(11,:big)
206
+ int_be.to_s.should == "\x00\x00\x00\x0b"
207
+ int_le = StructFu::Int32.new(11,:little)
208
+ int_le.to_s.should == "\x0b\x00\x00\x00"
209
+ end
210
+
211
+ it "should be able to switch endianness" do
212
+ @int.endian.should == :big
213
+ @int.to_s.should == "\x00\x00\x00\x0b"
214
+ @int.endian = :little
215
+ @int.endian.should == :little
216
+ @int.read(11)
217
+ @int.to_s.should == "\x0b\x00\x00\x00"
218
+ end
220
219
 
221
220
  end
222
221
 
223
222
  describe StructFu::Int32le, "4 byte little-endian value" do
224
223
 
225
- before :each do
226
- @int = StructFu::Int32le.new(11)
227
- end
224
+ before :each do
225
+ @int = StructFu::Int32le.new(11)
226
+ end
228
227
 
229
- it "should behave pretty much like any other 32 bit int" do
230
- @int.to_s.should == "\x0b\x00\x00\x00"
231
- end
228
+ it "should behave pretty much like any other 32 bit int" do
229
+ @int.to_s.should == "\x0b\x00\x00\x00"
230
+ end
232
231
 
233
- it "should raise when you try to change endianness" do
234
- expect { @int.endian = :big }.to raise_error
235
- expect { @int.endian = :little }.to raise_error
236
- end
232
+ it "should raise when you try to change endianness" do
233
+ expect { @int.endian = :big }.to raise_error(NoMethodError, /undefined method `endian='/)
234
+ expect { @int.endian = :little }.to raise_error(NoMethodError, /undefined method `endian='/)
235
+ end
237
236
 
238
237
  end
239
238
 
240
239
  describe StructFu::Int32be, "4 byte big-endian value" do
241
240
 
242
- before :each do
243
- @int = StructFu::Int32be.new(11)
244
- end
241
+ before :each do
242
+ @int = StructFu::Int32be.new(11)
243
+ end
245
244
 
246
- it "should behave pretty much like any other 32 bit int" do
247
- @int.to_s.should == "\x00\x00\x00\x0b"
248
- end
245
+ it "should behave pretty much like any other 32 bit int" do
246
+ @int.to_s.should == "\x00\x00\x00\x0b"
247
+ end
249
248
 
250
- it "should raise when you try to change endianness" do
251
- expect { @int.endian = :big }.to raise_error
252
- expect { @int.endian = :little }.to raise_error
253
- end
249
+ it "should raise when you try to change endianness" do
250
+ expect { @int.endian = :big }.to raise_error(NoMethodError, /undefined method `endian='/)
251
+ expect { @int.endian = :little }.to raise_error(NoMethodError, /undefined method `endian='/)
252
+ end
254
253
 
255
254
  end
256
255
 
257
256
  describe StructFu::String, "a sligtly more special String" do
258
257
 
259
- before :each do
260
- @str = StructFu::String.new("Oi, a string")
261
- end
258
+ before :each do
259
+ @str = StructFu::String.new("Oi, a string")
260
+ end
262
261
 
263
- it "should behave pretty much like a string" do
264
- @str.should be_kind_of(String)
265
- end
262
+ it "should behave pretty much like a string" do
263
+ @str.should be_kind_of(String)
264
+ end
266
265
 
267
- it "should have a read method" do
268
- @str.should respond_to(:read)
269
- end
266
+ it "should have a read method" do
267
+ @str.should respond_to(:read)
268
+ end
270
269
 
271
- it "should read data like other StructFu things" do
272
- @str.read("hello")
273
- @str.should == "hello"
274
- end
270
+ it "should read data like other StructFu things" do
271
+ @str.read("hello")
272
+ @str.should == "hello"
273
+ end
275
274
 
276
275
  end
277
276
 
278
277
  describe StructFu::IntString do
279
278
 
280
- it "should be" do
281
- StructFu::IntString.should be
282
- end
283
-
284
- it "should have a length and value" do
285
- istr = StructFu::IntString.new("Avast!")
286
- istr.to_s.should == "\x06Avast!"
287
- end
288
-
289
- it "should have a 16-bit length and a value" do
290
- istr = StructFu::IntString.new("Avast!",StructFu::Int16)
291
- istr.to_s.should == "\x00\x06Avast!"
292
- end
293
-
294
- it "should have a 32-bit length and a value" do
295
- istr = StructFu::IntString.new("Avast!",StructFu::Int32)
296
- istr.to_s.should == "\x00\x00\x00\x06Avast!"
297
- end
298
-
299
- before :each do
300
- @istr = StructFu::IntString.new("Avast!",StructFu::Int32)
301
- end
302
-
303
- it "should report the correct length with a new string" do
304
- @istr.to_s.should == "\x00\x00\x00\x06Avast!"
305
- @istr.string = "Ahoy!"
306
- @istr.to_s.should == "\x00\x00\x00\x05Ahoy!"
307
- end
308
-
309
- it "should report the correct length with a new string" do
310
- @istr.string = "Ahoy!"
311
- @istr.to_s.should == "\x00\x00\x00\x05Ahoy!"
312
- end
313
-
314
- it "should keep the old length with a new string" do
315
- @istr[:string] = "Ahoy!"
316
- @istr.to_s.should == "\x00\x00\x00\x06Ahoy!"
317
- end
318
-
319
- it "should allow for adjusting the length manually" do
320
- @istr.len = 16
321
- @istr.to_s.should == "\x00\x00\x00\x10Avast!"
322
- end
323
-
324
- it "should read in an expected string" do
325
- data = "\x00\x00\x00\x09Yo ho ho!"
326
- @istr.read(data)
327
- @istr.to_s.should == data
328
- end
329
-
330
- it "should raise when a string is too short" do
331
- data = "\x01A"
332
- expect { @istr.read(data) }.to raise_error
333
- end
279
+ it "should be" do
280
+ StructFu::IntString.should be
281
+ end
282
+
283
+ it "should have a length and value" do
284
+ istr = StructFu::IntString.new("Avast!")
285
+ istr.to_s.should == "\x06Avast!"
286
+ end
287
+
288
+ it "should have a 16-bit length and a value" do
289
+ istr = StructFu::IntString.new("Avast!",StructFu::Int16)
290
+ istr.to_s.should == "\x00\x06Avast!"
291
+ end
292
+
293
+ it "should have a 32-bit length and a value" do
294
+ istr = StructFu::IntString.new("Avast!",StructFu::Int32)
295
+ istr.to_s.should == "\x00\x00\x00\x06Avast!"
296
+ end
297
+
298
+ before :each do
299
+ @istr = StructFu::IntString.new("Avast!",StructFu::Int32)
300
+ end
301
+
302
+ it "should report the correct length with a new string" do
303
+ @istr.to_s.should == "\x00\x00\x00\x06Avast!"
304
+ @istr.string = "Ahoy!"
305
+ @istr.to_s.should == "\x00\x00\x00\x05Ahoy!"
306
+ end
307
+
308
+ it "should report the correct length with a new string" do
309
+ @istr.string = "Ahoy!"
310
+ @istr.to_s.should == "\x00\x00\x00\x05Ahoy!"
311
+ end
312
+
313
+ it "should keep the old length with a new string" do
314
+ @istr[:string] = "Ahoy!"
315
+ @istr.to_s.should == "\x00\x00\x00\x06Ahoy!"
316
+ end
317
+
318
+ it "should allow for adjusting the length manually" do
319
+ @istr.len = 16
320
+ @istr.to_s.should == "\x00\x00\x00\x10Avast!"
321
+ end
322
+
323
+ it "should read in an expected string" do
324
+ data = "\x00\x00\x00\x09Yo ho ho!"
325
+ @istr.read(data)
326
+ @istr.to_s.should == data
327
+ end
328
+
329
+ it "should raise when a string is too short" do
330
+ data = "\x01A"
331
+ expect { @istr.read(data) }.to raise_error(StandardError, "String is too short for type StructFu::Int32")
332
+ end
334
333
 
335
334
  end