Module: Crypto::Auth
- Extended by:
- FFI::Library, Sodium::Utils
- Defined in:
- lib/crypto/auth.rb
Constant Summary collapse
- PRIMITIVE =
primitive.freeze
- BYTES =
bytes.freeze
- KEYBYTES =
keybytes.freeze
Constants included from Sodium::Utils
Sodium::Utils::HEXY, Sodium::Utils::ZERO
Class Method Summary collapse
Methods included from Sodium::Utils
bin2hex, check_length, get_size, hex2bin, zeros
Class Method Details
.auth(message, key) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/crypto/auth.rb', line 25 def auth(, key) check_length(key, KEYBYTES, :SecretKey) mac = zeros(BYTES) key.readonly if key.is_a?(Sodium::SecretBuffer) crypto_auth(mac, , get_size(), key) mac ensure key.noaccess if key.is_a?(Sodium::SecretBuffer) end |
.verify(mac, message, key) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/crypto/auth.rb', line 37 def verify(mac, , key) check_length(mac, BYTES, :Mac) check_length(key, KEYBYTES, :SecretKey) key.readonly if key.is_a?(Sodium::SecretBuffer) crypto_auth_verify(mac, , get_size(), key) == 0 ensure key.noaccess if key.is_a?(Sodium::SecretBuffer) end |