Class: CryptBufferInputConverter
- Inherits:
-
Object
- Object
- CryptBufferInputConverter
- Defined in:
- lib/crypto-toolbox/crypt_buffer_input_converter.rb
Defined Under Namespace
Classes: ImpossibleConversion, InvalidHexstring
Instance Method Summary collapse
- #convert(input) ⇒ Object
- #from_base64(input) ⇒ Object
-
#from_hex(input) ⇒ Object
Make sure input strings are always interpreted as hex strings This is especially useful for unknown or uncertain inputs like strings with or without leading 0x.
Instance Method Details
#convert(input) ⇒ Object
6 7 8 |
# File 'lib/crypto-toolbox/crypt_buffer_input_converter.rb', line 6 def convert(input) bytes_from_any(input) end |
#from_base64(input) ⇒ Object
22 23 24 25 |
# File 'lib/crypto-toolbox/crypt_buffer_input_converter.rb', line 22 def from_base64(input) string = Base64.decode64(input) CryptBuffer.new(str2bytes(string)) end |
#from_hex(input) ⇒ Object
Make sure input strings are always interpreted as hex strings This is especially useful for unknown or uncertain inputs like strings with or without leading 0x
13 14 15 16 17 18 19 20 |
# File 'lib/crypto-toolbox/crypt_buffer_input_converter.rb', line 13 def from_hex(input) raise InvalidHexstring, "input: #{input} is not a valid hexadicimal string" unless valid_hexstring?(input) hexstr ="" unless input.nil? hexstr = normalize_hex(input) end CryptBuffer.new(hex2bytes(hexstr)) end |