dohruby 0.3.6 → 0.3.7
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.
- data/lib/doh/core/string.rb +9 -2
- metadata +2 -2
data/lib/doh/core/string.rb
CHANGED
@@ -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
|
-
|
96
|
-
|
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
|