grizzly_ber 1.0.7 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/grizzly_ber.rb +13 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1b181cdaf383957407f7ab5c1277d5afebbbbdc
|
4
|
+
data.tar.gz: a0d9f7ade92b3b805167ad4740169eab216b01ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07166fd51c1a96ef44bcea69a99b6b12d63bbac0d51143b4d0fc9cbd20ac44d722c8f1736c0c753f57ff6578e7f46a7a59ec4a49a0eb4c721c2235f35f0891dd
|
7
|
+
data.tar.gz: c26cdd7fc85f05e355fa18811da938cdc780d9b95922561753dc65f0369b2789dac0ddc9fb2ef98c16a358ef7c749d194e7ced3c6eb2be20800c3e0e769ae1f9
|
data/lib/grizzly_ber.rb
CHANGED
@@ -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
|
-
|
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.
|
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
|
-
|
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
|