dohruby 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/doh/core/string.rb +9 -2
  2. metadata +2 -2
@@ -83,6 +83,7 @@ class String
83
83
  end
84
84
 
85
85
  def hex_decode
86
+ raise 'invalid hex string length' if (self.length % 2) != 0
86
87
  byte_array = []
87
88
  upcase.chars.each_slice(2) do |slice|
88
89
  byte_array.push(hex_to_int(slice[0].getbyte(0))*16 + hex_to_int(slice[1].getbyte(0)))
@@ -92,8 +93,14 @@ class String
92
93
 
93
94
  private
94
95
  def hex_to_int(byte)
95
- return byte - 48 if byte < 60
96
- return byte - 55
96
+ result = 0
97
+ if byte < 60
98
+ result = byte - 48
99
+ else
100
+ result = byte - 55
101
+ end
102
+ raise "invalid hex character #{byte}" if result < 0 || result > 15
103
+ result
97
104
  end
98
105
 
99
106
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 6
9
- version: 0.3.6
8
+ - 7
9
+ version: 0.3.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Makani & Kem Mason