crypto-toolbox 0.0.13 → 0.0.14
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 +4 -4
- data/lib/crypto-toolbox/crypt_buffer.rb +15 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 855fa68c984b157e774117b3cd5806d11afdc0ba
|
4
|
+
data.tar.gz: 8a4fd65dceaa6d7490e8f9865da8cdc5cddfa2b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b415280b51fc55662ae73195f271d0547b7ad49a065f5f5a4e1172ec6ec8af34875bbbf493673e15e359ebf9e9bd677e923060fede837839c1ada96d61ae13bd
|
7
|
+
data.tar.gz: 3c166e9f450962718f61be0a2daac7d0fd647a426ce7ea4dee8cddcfe08b0f8b8ea8a396ccb8e290f22b835e8bbe0a82f80701a82f3c03f82250a4f69b5fcae3
|
@@ -13,6 +13,17 @@ class CryptBuffer
|
|
13
13
|
@bytes = bytes_from_any(input)
|
14
14
|
end
|
15
15
|
|
16
|
+
# Make sure input strings are always interpreted as hex strings
|
17
|
+
# This is especially useful for unknown or uncertain inputs like
|
18
|
+
# strings with or without leading 0x
|
19
|
+
def self.from_hex(input)
|
20
|
+
hexstr =""
|
21
|
+
unless input.nil?
|
22
|
+
hexstr = (input =~ /^0x/ ? input : "0x#{pad_hex_char(input)}" )
|
23
|
+
end
|
24
|
+
CryptBuffer.new(hexstr)
|
25
|
+
end
|
26
|
+
|
16
27
|
def each(&block)
|
17
28
|
@bytes.each(&block)
|
18
29
|
end
|
@@ -142,8 +153,11 @@ class CryptBuffer
|
|
142
153
|
end
|
143
154
|
end
|
144
155
|
|
156
|
+
def self.pad_hex_char(str)
|
157
|
+
(str.length == 1) ? "0#{str}" : "#{str}"
|
158
|
+
end
|
145
159
|
def normalize_hex(str)
|
146
|
-
tmp = (str
|
160
|
+
tmp = self.class.pad_hex_char(str)
|
147
161
|
tmp.gsub(/(^0x|\s)/,"").upcase
|
148
162
|
end
|
149
163
|
|