funky-tlv 0.2.2 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 536e6721d21a76d3f02ebc151dee1b3274c4b706
4
- data.tar.gz: 6f42870f750d4ed8d8e3a205107889350b15c59f
3
+ metadata.gz: 514dd2637b1f8da8761428316299ee5d6ad61be8
4
+ data.tar.gz: 4fa492e814838d192f3137d7f57f53f955cfbb1d
5
5
  SHA512:
6
- metadata.gz: 2cf3bb7c1bfb768d6917093e6f098fa0522e8cf9bb1f62a80dafd2d088a666b727bb75267b1202336746619714066d2acb6cdced6524ec742d216d5d1c6aa245
7
- data.tar.gz: 6869ce01c1d16e1275743304868bb6dcd4ca3c20bbfbb9e0c84cb1a37b91e4df873331814a30ee18fb902960c7b1f4038359bea57068d5923aa6b8a9c10b753f
6
+ metadata.gz: 4e34605f846673f464cf6c2864c09e271f6e38f9fdfdd87cb42a82531fc747d9ec0f240fcd58d2ebfba71cb2cee2ceaaad53e8d2455561be32ad874ea0551fc0
7
+ data.tar.gz: 8b970ede579dc2807c179fcf6120f336675da369273e657cf6eae8c6b125594cb41f08cd23b07d128eb5c9d98cdd74d65f11f4ff5f25bfdaf6fee3c134a73a9b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- funky-tlv (0.2.2)
4
+ funky-tlv (0.2.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -27,4 +27,4 @@ DEPENDENCIES
27
27
  rake (~> 10.0)
28
28
 
29
29
  BUNDLED WITH
30
- 1.12.3
30
+ 1.15.1
data/Rakefile CHANGED
@@ -8,6 +8,6 @@ Bundler.require(:default)
8
8
 
9
9
  DaFunk::RakeTask.new do |t|
10
10
  t.mrbc = "cloudwalk compile"
11
- t.mruby = "cloudwalk run"
11
+ t.mruby = "cloudwalk run -b"
12
12
  end
13
13
 
@@ -1,4 +1,4 @@
1
1
  module FunkyTlv
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
4
4
 
@@ -1,68 +1,68 @@
1
1
  # encoding: utf-8
2
2
  class Hash
3
- def from_ber_tlv(data)
4
- i = 0
5
- tag = data[i]
6
- if tag.unpack('C').pop & 0x1F == 0x1F # matches 00011111 mask?
7
- begin
8
- i += 1
9
- tag[i] = data[i]
10
- end while tag[i].unpack('C').pop & 0x80 == 0x80
11
- end
3
+ def from_ber_tlv(data)
4
+ i = 0
5
+ tag = data[i]
6
+ if (tag.unpack('C').pop & 0x1F) == 0x1F # matches 00011111 mask?
7
+ loop do
8
+ i += 1
9
+ tag[i] = data[i]
10
+ break unless (tag[i].unpack('C').pop & 0x80) == 0x80
11
+ end
12
+ end
12
13
 
13
- length = data[tag.length].unpack('C').pop
14
+ length = data[tag.length].unpack('C').pop
14
15
 
15
- tag_i = tag.unpack('H*').pop.to_i(16)
16
+ tag_i = tag.unpack('H*').pop.to_i(16)
16
17
 
17
- if length < 0x80
18
- self[tag_i] = data[tag.length + 1, length]
19
- remainder = data[tag.length + 1 + length..-1]
20
- else
21
- num_octets = length & 0x7f
22
- octets = data[tag.length + 1, num_octets].unpack('C*')
18
+ if length < 0x80
19
+ self[tag_i] = data[tag.length + 1, length]
20
+ remainder = data[tag.length + 1 + length..-1]
21
+ else
22
+ num_octets = length & 0x7f
23
+ octets = data[tag.length + 1, num_octets].unpack('C*')
23
24
 
24
- length = 0
25
- octets.reverse.each_with_index {|octet, idx|
26
- length += octet * (256**idx)
27
- }
25
+ length = 0
26
+ octets.reverse.each_with_index {|octet, idx|
27
+ length += octet * (256**idx)
28
+ }
28
29
 
29
- self[tag_i] = data[tag.length + 1 + num_octets, length]
30
- remainder = data[tag.length + 1 + num_octets + length..-1]
31
- end
30
+ self[tag_i] = data[tag.length + 1 + num_octets, length]
31
+ remainder = data[tag.length + 1 + num_octets + length..-1]
32
+ end
32
33
 
33
- if remainder and remainder.length > 2
34
- self.from_ber_tlv(remainder)
35
- end
34
+ if remainder and remainder.length > 2
35
+ self.from_ber_tlv(remainder)
36
+ end
36
37
 
37
- self
38
- end
38
+ self
39
+ end
39
40
 
40
- def to_ber_tlv
41
- result = ''
42
- self.each do |tag, value|
43
- v = value.dup
44
- result << int_to_binstr(tag) # adding tag to result string
41
+ def to_ber_tlv
42
+ result = ''
43
+ self.each do |tag, value|
44
+ v = value.dup
45
+ result << int_to_binstr(tag) # adding tag to result string
45
46
 
46
- #adding size of the tag
47
- if v.size < 0x80
48
- result << int_to_binstr(v.size)
49
- else
50
- len_len = int_to_binstr(v.size)
51
- result << int_to_binstr(0x80 | len_len.size)
52
- result << len_len
53
- end
47
+ #adding size of the tag
48
+ if v.size < 0x80
49
+ result << int_to_binstr(v.size)
50
+ else
51
+ len_len = int_to_binstr(v.size)
52
+ result << int_to_binstr(0x80 | len_len.size)
53
+ result << len_len
54
+ end
54
55
 
55
- result << v
56
- end
56
+ result << v
57
+ end
57
58
 
58
- result
59
- end
59
+ result
60
+ end
60
61
 
61
- # converts integer to binary string representation
62
- def int_to_binstr(i)
63
- binstr = "%X" % i
64
- binstr = '0' << binstr if binstr.size % 2 == 1
65
- [binstr].pack('H*').force_encoding("UTF-8")
66
- end
62
+ # converts integer to binary string representation
63
+ def int_to_binstr(i)
64
+ binstr = "%X" % i
65
+ binstr = '0' << binstr if binstr.size % 2 == 1
66
+ [binstr].pack('H*')
67
+ end
67
68
  end
68
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funky-tlv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago Scalone
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-20 00:00:00.000000000 Z
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 2.5.1
77
+ rubygems_version: 2.6.12
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Hash Ber TLV implementation