packetgen 3.1.6 → 3.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8959dbe60df80490d1ac31eaf40b05a206860bf6bed306997a66ca9c77dfb0b
4
- data.tar.gz: 4615a1084f86e4b0ab216b3766dbde7d1b0b2b1e3c2e6b0d2e1a63aba1ff7bd6
3
+ metadata.gz: 6297501a0b2bbf2242e1481e52183c961d694306611cc7b61db46aaac59cb399
4
+ data.tar.gz: b9af651662460d50c7ea93030f171469d5efbc85759df27e6fa25d6870f6f5b8
5
5
  SHA512:
6
- metadata.gz: 636f0dcea926b57cb7ec7a824744dfbcab9c6ddbb7f6749d8fda8f63fec410d20dcf199f362ae63878104725e94c7075d17f94b3f0dc8458b3d975e9521343da
7
- data.tar.gz: 50e679400b1f882fbe2d3bc9e3ba5e01bb24dbe4a83b3372b999cbe0d1565703a7fc6afc08c437900e23b92c549c46ad422e3e76140254034c8840ba3a8ecb2e
6
+ metadata.gz: b1dea6fa78201583d40f94439943a217deeea8fd6b7485a6fd0a748c802fd6f0d3f25b82e7dcf24e525dd93634a111ae49c4437fde73b6e51ab4d37070346dcb
7
+ data.tar.gz: ca4b7bd3596d9e50ab6cc9d3bbcaeb9127544509badb2371eab71466cbe85efdfe4060ccb072c1724bf1240c427fc27ab4ace581250fdb79d1c0c5bf5d7f32ed
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
 
2
2
  [![Gem Version](https://badge.fury.io/rb/packetgen.svg)](https://badge.fury.io/rb/packetgen)
3
- [![Build Status](https://travis-ci.org/sdaubert/packetgen.svg?branch=master)](https://travis-ci.org/sdaubert/packetgen)
4
3
 
5
4
  # PacketGen
6
5
 
@@ -17,8 +17,9 @@ module PacketGen
17
17
  extend Forwardable
18
18
  include Fieldable
19
19
 
20
- def_delegators :@string, :[], :length, :size, :inspect, :==, :<<,
21
- :unpack, :force_encoding, :encoding, :index, :empty?
20
+ def_delegators :@string, :[], :length, :size, :inspect, :==,
21
+ :unpack, :force_encoding, :encoding, :index, :empty?,
22
+ :encode, :slice, :slice!
22
23
 
23
24
  # @return [::String]
24
25
  attr_reader :string
@@ -28,7 +29,7 @@ module PacketGen
28
29
  # @param [Hash] options
29
30
  # @option options [Integer] :static_length set a static length for this string
30
31
  def initialize(options={})
31
- register_internal_string ''
32
+ register_internal_string(+'')
32
33
  @static_length = options[:static_length]
33
34
  end
34
35
 
@@ -37,9 +38,8 @@ module PacketGen
37
38
  def read(str)
38
39
  s = str.to_s
39
40
  s = s[0, static_length] if static_length?
40
- idx = s.index(0.chr)
41
- s = s[0, idx] unless idx.nil?
42
41
  register_internal_string s
42
+ remove_null_character
43
43
  self
44
44
  end
45
45
 
@@ -55,6 +55,15 @@ module PacketGen
55
55
  PacketGen.force_binary(s)
56
56
  end
57
57
 
58
+ # Append the given string to CString
59
+ # @param [#to_s] str
60
+ # @return [self]
61
+ def <<(str)
62
+ @string << str.to_s
63
+ remove_null_character
64
+ self
65
+ end
66
+
58
67
  # @return [Integer]
59
68
  def sz
60
69
  if static_length?
@@ -80,8 +89,7 @@ module PacketGen
80
89
 
81
90
  # @return [String]
82
91
  def to_human
83
- idx = self.index(+"\x00".encode(self.encoding)) || self.sz
84
- self[0, idx]
92
+ string
85
93
  end
86
94
 
87
95
  private
@@ -90,6 +98,11 @@ module PacketGen
90
98
  @string = str
91
99
  PacketGen.force_binary(@string)
92
100
  end
101
+
102
+ def remove_null_character
103
+ idx = string.index(0.chr)
104
+ register_internal_string(string[0, idx]) unless idx.nil?
105
+ end
93
106
  end
94
107
  end
95
108
  end
@@ -18,8 +18,9 @@ module PacketGen
18
18
  include Fieldable
19
19
  include LengthFrom
20
20
 
21
- def_delegators :@string, :[], :to_s, :length, :size, :inspect, :==, :<<,
22
- :unpack, :force_encoding, :encoding, :index, :empty?
21
+ def_delegators :@string, :[], :to_s, :length, :size, :inspect, :==,
22
+ :unpack, :force_encoding, :encoding, :index, :empty?,
23
+ :encode, :slice, :slice!, :[]=
23
24
 
24
25
  # @return [::String]
25
26
  attr_reader :string
@@ -31,11 +32,15 @@ module PacketGen
31
32
  # takes length when reading
32
33
  # @option options [Integer] :static_length set a static length for this string
33
34
  def initialize(options={})
34
- register_internal_string ''
35
+ register_internal_string(+'')
35
36
  initialize_length_from(options)
36
37
  @static_length = options[:static_length]
37
38
  end
38
39
 
40
+ def initialize_copy(_orig)
41
+ @string = @string.dup
42
+ end
43
+
39
44
  # @param [::String] str
40
45
  # @return [String] self
41
46
  def read(str)
@@ -68,6 +73,14 @@ module PacketGen
68
73
  inspect
69
74
  end
70
75
 
76
+ # Append the given string to String
77
+ # @param [#to_s] str
78
+ # @return [self]
79
+ def <<(str)
80
+ @string << str.to_s
81
+ self
82
+ end
83
+
71
84
  alias sz length
72
85
  alias to_human to_s
73
86
  alias from_human read
@@ -10,5 +10,5 @@
10
10
  # @author Sylvain Daubert
11
11
  module PacketGen
12
12
  # PacketGen version
13
- VERSION = '3.1.6'
13
+ VERSION = '3.1.7'
14
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packetgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.6
4
+ version: 3.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Daubert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-04 00:00:00.000000000 Z
11
+ date: 2020-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: interfacez