crypto-toolbox 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 403cf818e558bf451d876c20fbbb90cdff55a573
4
- data.tar.gz: cd70a45a5d69397d691bd08a7eb5069affdbba1e
3
+ metadata.gz: 855fa68c984b157e774117b3cd5806d11afdc0ba
4
+ data.tar.gz: 8a4fd65dceaa6d7490e8f9865da8cdc5cddfa2b6
5
5
  SHA512:
6
- metadata.gz: 823cc7f89d4e7913affde18355b49b7a63415885c43a413f462e22b91c31b42f48f7ca9459f735a581a12dd9a41405ad8807f5d9ec61a82c9d8b3c38643b8c6b
7
- data.tar.gz: 168e3ae351b6e89a006b956ca49e7ba02c431875f383880e7729db3582261606659261239ff5be724cf438e9c31f438359c9848fd186fb4451884d057926534d
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.length == 1) ? "0#{str}" : "#{str}"
160
+ tmp = self.class.pad_hex_char(str)
147
161
  tmp.gsub(/(^0x|\s)/,"").upcase
148
162
  end
149
163
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crypto-toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Sivia