grizzly_ber 1.0.7 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/grizzly_ber.rb +13 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7ae8c4643321026428536cfc08fed20ce944673
4
- data.tar.gz: f0acebc235b93408dcb1623e2f848f73a0eb5b2d
3
+ metadata.gz: e1b181cdaf383957407f7ab5c1277d5afebbbbdc
4
+ data.tar.gz: a0d9f7ade92b3b805167ad4740169eab216b01ed
5
5
  SHA512:
6
- metadata.gz: fcd71e845da7713695b9f22d23a76c7779ca85ffed32ae6b150ffe02b875b406c909b8ca8af52f58d6b406fb5a4068a9b4806da92f0a2df0b4f41868eb62b5b5
7
- data.tar.gz: 1af7fa7e474446f1ab06732a6a1d7abef9d4776425b379b5ce2e328a969d43ccfd15fdd7c81be1c99cba1879970223951a44658eb350706e442572516df64772
6
+ metadata.gz: 07166fd51c1a96ef44bcea69a99b6b12d63bbac0d51143b4d0fc9cbd20ac44d722c8f1736c0c753f57ff6578e7f46a7a59ec4a49a0eb4c721c2235f35f0891dd
7
+ data.tar.gz: c26cdd7fc85f05e355fa18811da938cdc780d9b95922561753dc65f0369b2789dac0ddc9fb2ef98c16a358ef7c749d194e7ced3c6eb2be20800c3e0e769ae1f9
@@ -60,7 +60,6 @@ class GrizzlyBerElement
60
60
  end
61
61
 
62
62
  def decode_tag(byte_array)
63
- byte_array.shift while byte_array.size > 0 and (byte_array[0] == 0x00 or byte_array[0] == 0xFF)
64
63
  return [] if byte_array.size < 1
65
64
 
66
65
  first_byte = byte_array.shift
@@ -104,9 +103,13 @@ end
104
103
  class GrizzlyBer
105
104
  include Enumerable
106
105
 
107
- def initialize(hex_string = "")
106
+ class ParsingError < StandardError
107
+ end
108
+
109
+ def initialize(hex_string = "", allow_FF_tags: false)
108
110
  raise ArgumentError, "hex_string must be a valid hex string" unless hex_string.is_a? String and hex_string.size.even? and hex_string =~ /^[0-9A-F]*$/
109
111
  @elements = [] # is an array of GrizzlyBerElement
112
+ @allow_FF_tags = allow_FF_tags
110
113
  from_ber_hex_string(hex_string)
111
114
  end
112
115
 
@@ -117,11 +120,14 @@ class GrizzlyBer
117
120
 
118
121
  def from_ber(byte_array)
119
122
  raise ArgumentError, "byte_array must be an array of bytes" unless byte_array.is_a? Array and byte_array.all? {|byte| byte.is_a? Integer and byte <= 0xFF}
120
- while byte_array.size > 0
123
+ while byte_array.any?
124
+ byte_array.shift while byte_array.any? && is_erasure_byte(byte_array[0])
125
+ break if byte_array.empty?
121
126
  element = GrizzlyBerElement.new(byte_array)
122
- break if element.tag.nil? or element.value.nil?
127
+ raise ParsingError if element.tag.nil? or element.value.nil?
123
128
  @elements << element
124
129
  end
130
+ raise ParsingError if byte_array.any?
125
131
  self
126
132
  end
127
133
 
@@ -201,5 +207,8 @@ class GrizzlyBer
201
207
 
202
208
  private
203
209
 
210
+ def is_erasure_byte(byte)
211
+ byte == 0x00 || (!@allow_FF_tags && byte == 0xFF)
212
+ end
204
213
 
205
214
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grizzly_ber
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Balsdon