class Blake2::Key
Validate and normalize an HMAC key, provided in different formats, into an Array of Integer Bytes.
Attributes
bytes[R]
Public Class Methods
from_bytes(bytes)
click to toggle source
Create a key from Array of Integer (0-255) Bytes. This simply validates and passes through the Array.
@param str [Array] an Array of Integer (0-255) Bytes @return [Blake2::Key] a Blake2::Key
object with a `bytes` attr
# File lib/blake2/key.rb, line 47 def self.from_bytes(bytes) if bytes.all? { |b| b.is_a?(Integer) && b.between?(0, 255) } new(bytes) else raise ArgumentError, 'key must be a Byte Array of Integers (0-255)' end end
from_hex(str)
click to toggle source
Create a key from a Hex String [a-fA-F0-9]
@param str [String] a Hex String key @return [Blake2::Key] a Blake2::Key
object with a `bytes` attr
# File lib/blake2/key.rb, line 34 def self.from_hex(str) if str.is_a?(String) && str.match(/^[a-fA-F0-9]+$/) new([str].pack('H*').bytes) else raise ArgumentError, 'key must be a Hex String [a-fA-F0-9]' end end
from_string(str)
click to toggle source
Create a key from an ASCII String
@param str [String] an ASCII String key @return [Blake2::Key] a Blake2::Key
object with a `bytes` attr
# File lib/blake2/key.rb, line 22 def self.from_string(str) if str.is_a?(String) && str.ascii_only? new(str.bytes) else raise ArgumentError, 'key must be an ASCII String' end end
new(bytes)
click to toggle source
# File lib/blake2/key.rb, line 7 def initialize(bytes) @bytes = bytes end
none()
click to toggle source
Create a blank Key
@return [Blake2::Key] a Blake2::Key
object with a `bytes` attr
# File lib/blake2/key.rb, line 14 def self.none new([]) end