grizzly_ber 1.0.7 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/grizzly_ber.rb +16 -5
- data/lib/grizzly_tag.rb +2 -0
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 363bdd214a4f6ab85f7555590b98e79fecba9ee871ac0f14240f4925fb0a6049
|
4
|
+
data.tar.gz: 771e82bdcaed2d527870712c784a20c181dcbb27f18771e931e85acf50b679bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4caed519208405e3ff3a4c00351ebb1427e32181d2bb4a7ff48cc991011d2b94320c313b1afa9bd2881a6a246e0496f62d26f39b7f41c6f4b9059fc5814d8eb9
|
7
|
+
data.tar.gz: 13cb98e5a5f75ea43a501183487daacc87bb4e30447bcd6c4a712a077d24531dd4effc99e35dc09349629cc57b1d3bace67ef5e7cd6a30b9d84925394f64bed3
|
data/lib/grizzly_ber.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'grizzly_tag'
|
2
4
|
|
3
5
|
class GrizzlyBerElement
|
@@ -5,7 +7,7 @@ class GrizzlyBerElement
|
|
5
7
|
|
6
8
|
def initialize(byte_array = [])
|
7
9
|
raise ArgumentError, "byte_array must be of type Array" unless byte_array.is_a?(Array)
|
8
|
-
@tag = "" # is an uppercase hex string
|
10
|
+
@tag = +"" # is an uppercase hex string
|
9
11
|
@value = nil # is a byte array if this is a data element or a GrizzlyBer if it's a sequence element
|
10
12
|
decode_value decode_length decode_tag byte_array
|
11
13
|
end
|
@@ -60,7 +62,6 @@ class GrizzlyBerElement
|
|
60
62
|
end
|
61
63
|
|
62
64
|
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
65
|
return [] if byte_array.size < 1
|
65
66
|
|
66
67
|
first_byte = byte_array.shift
|
@@ -104,9 +105,13 @@ end
|
|
104
105
|
class GrizzlyBer
|
105
106
|
include Enumerable
|
106
107
|
|
107
|
-
|
108
|
+
class ParsingError < StandardError
|
109
|
+
end
|
110
|
+
|
111
|
+
def initialize(hex_string = "", allow_FF_tags: false)
|
108
112
|
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
113
|
@elements = [] # is an array of GrizzlyBerElement
|
114
|
+
@allow_FF_tags = allow_FF_tags
|
110
115
|
from_ber_hex_string(hex_string)
|
111
116
|
end
|
112
117
|
|
@@ -117,11 +122,14 @@ class GrizzlyBer
|
|
117
122
|
|
118
123
|
def from_ber(byte_array)
|
119
124
|
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.
|
125
|
+
while byte_array.any?
|
126
|
+
byte_array.shift while byte_array.any? && is_erasure_byte(byte_array[0])
|
127
|
+
break if byte_array.empty?
|
121
128
|
element = GrizzlyBerElement.new(byte_array)
|
122
|
-
|
129
|
+
raise ParsingError if element.tag.nil? or element.value.nil?
|
123
130
|
@elements << element
|
124
131
|
end
|
132
|
+
raise ParsingError if byte_array.any?
|
125
133
|
self
|
126
134
|
end
|
127
135
|
|
@@ -201,5 +209,8 @@ class GrizzlyBer
|
|
201
209
|
|
202
210
|
private
|
203
211
|
|
212
|
+
def is_erasure_byte(byte)
|
213
|
+
byte == 0x00 || (!@allow_FF_tags && byte == 0xFF)
|
214
|
+
end
|
204
215
|
|
205
216
|
end
|
data/lib/grizzly_tag.rb
CHANGED
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.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Balsdon
|
@@ -18,27 +18,29 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- lib/grizzly_ber.rb
|
20
20
|
- lib/grizzly_tag.rb
|
21
|
-
homepage:
|
21
|
+
homepage: https://github.com/Shopify/grizzly_ber
|
22
22
|
licenses:
|
23
23
|
- MIT
|
24
|
-
metadata:
|
24
|
+
metadata:
|
25
|
+
allowed_push_host: https://rubygems.org
|
26
|
+
homepage_uri: https://github.com/Shopify/grizzly_ber
|
27
|
+
source_code_uri: https://github.com/Shopify/grizzly_ber
|
25
28
|
post_install_message:
|
26
29
|
rdoc_options: []
|
27
30
|
require_paths:
|
28
31
|
- lib
|
29
32
|
required_ruby_version: !ruby/object:Gem::Requirement
|
30
33
|
requirements:
|
31
|
-
- -
|
34
|
+
- - ">="
|
32
35
|
- !ruby/object:Gem::Version
|
33
36
|
version: '0'
|
34
37
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
38
|
requirements:
|
36
|
-
- -
|
39
|
+
- - ">="
|
37
40
|
- !ruby/object:Gem::Version
|
38
41
|
version: '0'
|
39
42
|
requirements: []
|
40
|
-
|
41
|
-
rubygems_version: 2.0.14
|
43
|
+
rubygems_version: 3.5.7
|
42
44
|
signing_key:
|
43
45
|
specification_version: 4
|
44
46
|
summary: Fiercest TLV-BER parser
|