grizzly_ber 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/grizzly_ber.rb +18 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3a8c80071b42ae32018e13afe33c1d0669891a8
|
4
|
+
data.tar.gz: bfb24420adc9aeef6f73a8d08a6b739c0791f833
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ce15399e53924e379619676b5ec11dcc2f76300cd510e8b016ed9d3fffcdf046c57eb86838767172cd3a57d83a89d1898446111226c5d1528ea0afabb0345a4
|
7
|
+
data.tar.gz: 3e4699be345997b37e1cc0924d4ce2755b437869e30a772482f59ae55129180d6b4efe40fd9c5c3aedd7c7149876ad34195e81286579095a971acc8519f1c6bb
|
data/lib/grizzly_ber.rb
CHANGED
@@ -12,6 +12,7 @@ class GrizzlyBerElement
|
|
12
12
|
|
13
13
|
def tag=(tag)
|
14
14
|
raise ArgumentError, "tag must be a valid hex string" unless tag.is_a? String and tag.size.even? and tag =~ /^[0-9A-F]*$/
|
15
|
+
raise ArgumentError, "tag #{tag} must be a valid BER tag" unless tag_is_valid? tag
|
15
16
|
@tag = tag
|
16
17
|
end
|
17
18
|
|
@@ -39,6 +40,20 @@ class GrizzlyBerElement
|
|
39
40
|
|
40
41
|
private
|
41
42
|
|
43
|
+
def tag_is_valid?(tag_string)
|
44
|
+
tag_byte_array = [tag_string].pack("H*").unpack("C*")
|
45
|
+
return false if tag_byte_array.size < 1
|
46
|
+
|
47
|
+
first_byte = tag_byte_array.shift
|
48
|
+
return false if tag_byte_array.size > 0 and (first_byte & 0x1F) != 0x1F
|
49
|
+
|
50
|
+
last_byte = tag_byte_array.pop || 0x00
|
51
|
+
return false if (last_byte & 0x80) != 0x00
|
52
|
+
|
53
|
+
tag_byte_array.each {|byte| return false if (byte & 0x80) != 0x80 }
|
54
|
+
true
|
55
|
+
end
|
56
|
+
|
42
57
|
def byte_to_hex(byte)
|
43
58
|
byte.to_s(16).rjust(2,'0').upcase
|
44
59
|
end
|
@@ -145,12 +160,11 @@ class GrizzlyBer
|
|
145
160
|
end
|
146
161
|
|
147
162
|
def set_value_for_tag(tag, value)
|
148
|
-
tag.upcase
|
149
|
-
first_tagged_element = @elements.find {|element|
|
150
|
-
first_tagged_element ||= @elements.find {|element| element.tag == GrizzlyTag.named(tag)[:tag]} if GrizzlyTag.named(tag)
|
163
|
+
real_tag = GrizzlyTag.named(tag) ? GrizzlyTag.named(tag)[:tag] : tag.upcase
|
164
|
+
first_tagged_element = @elements.find {|element| real_tag == element.tag}
|
151
165
|
if first_tagged_element.nil?
|
152
166
|
first_tagged_element = GrizzlyBerElement.new
|
153
|
-
first_tagged_element.tag =
|
167
|
+
first_tagged_element.tag = real_tag
|
154
168
|
@elements << first_tagged_element
|
155
169
|
end
|
156
170
|
first_tagged_element.value = value
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grizzly_ber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Balsdon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: CODEC for EMV TLV-BER encoded strings.
|
14
14
|
email: ryan.balsdon@shopify.com
|
@@ -28,12 +28,12 @@ require_paths:
|
|
28
28
|
- lib
|
29
29
|
required_ruby_version: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
35
|
requirements:
|
36
|
-
- -
|
36
|
+
- - ">="
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: '0'
|
39
39
|
requirements: []
|