hash-ber-tlv 1.0.3 → 1.0.4

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.
Files changed (2) hide show
  1. data/lib/hash-ber-tlv.rb +12 -13
  2. metadata +20 -39
@@ -36,20 +36,22 @@ class Hash
36
36
  self
37
37
  end
38
38
 
39
- def to_ber_tlv
40
- result = ''
39
+ def to_ber_tlv
40
+ result = ''.force_encoding('ASCII-8BIT')
41
41
  self.each do |tag, value|
42
+ v = value.dup.force_encoding('ASCII-8BIT')
42
43
  result << int_to_binstr(tag) # adding tag to result string
43
- if value.length < 0x80
44
- result << int_to_binstr(value.length)
44
+
45
+ #adding size of the tag
46
+ if v.size < 0x80
47
+ result << int_to_binstr(v.size)
45
48
  else
46
- #calculate length of length :)
47
- len_len = int_to_binstr(value.length)
48
- result << int_to_binstr(0x80 | len_len.length)
49
+ len_len = int_to_binstr(v.size)
50
+ result << int_to_binstr(0x80 | len_len.size)
49
51
  result << len_len
50
52
  end
51
53
 
52
- result << value
54
+ result << v
53
55
  end
54
56
 
55
57
  result
@@ -57,11 +59,8 @@ class Hash
57
59
 
58
60
  # converts integer to binary string representation
59
61
  def int_to_binstr(i)
60
- binstr = i.to_s(16)
61
- if binstr.length % 2 == 1
62
- binstr = '0' << binstr
63
- end
64
-
62
+ binstr = "%X" % i
63
+ binstr = '0' << binstr if binstr.size % 2 == 1
65
64
  [binstr].pack('H*')
66
65
  end
67
66
  end
metadata CHANGED
@@ -1,64 +1,45 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hash-ber-tlv
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 0
8
- - 3
9
- version: 1.0.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Maxim Chechel
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-11-22 00:00:00 +04:00
18
- default_executable:
12
+ date: 2014-04-09 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
14
  description: Extend Hash class with ability to parse and convert BER TLV format
22
15
  email: maximchick@gmail.com
23
16
  executables: []
24
-
25
17
  extensions: []
26
-
27
18
  extra_rdoc_files: []
28
-
29
- files:
19
+ files:
30
20
  - lib/hash-ber-tlv.rb
31
- has_rdoc: true
32
21
  homepage: http://rubygems.org/gems/hash-ber-tlv
33
22
  licenses: []
34
-
35
23
  post_install_message:
36
24
  rdoc_options: []
37
-
38
- require_paths:
25
+ require_paths:
39
26
  - lib
40
- required_ruby_version: !ruby/object:Gem::Requirement
27
+ required_ruby_version: !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- segments:
46
- - 0
47
- version: "0"
48
- required_rubygems_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
34
  none: false
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
- version: "0"
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
56
39
  requirements: []
57
-
58
40
  rubyforge_project:
59
- rubygems_version: 1.3.7
41
+ rubygems_version: 1.8.25
60
42
  signing_key:
61
43
  specification_version: 3
62
- summary: ""
44
+ summary: ''
63
45
  test_files: []
64
-