Class: Sodium::OneTimeAuth
- Inherits:
-
Object
- Object
- Sodium::OneTimeAuth
- Includes:
- Delegate
- Defined in:
- lib/sodium/one_time_auth.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(key) ⇒ OneTimeAuth
constructor
A new instance of OneTimeAuth.
- #one_time_auth(message) ⇒ Object
- #verify(message, authenticator) ⇒ Object
Methods included from Delegate
class_methods, included, #primitive
Constructor Details
#initialize(key) ⇒ OneTimeAuth
Returns a new instance of OneTimeAuth.
10 11 12 |
# File 'lib/sodium/one_time_auth.rb', line 10 def initialize(key) @key = self.class._key(key) end |
Class Method Details
Instance Method Details
#one_time_auth(message) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sodium/one_time_auth.rb', line 14 def one_time_auth() = self.class.() Sodium::Buffer.empty self.implementation[:BYTES] do |authenticator| self.implementation.nacl( authenticator.to_ptr, .to_ptr, .bytesize, @key .to_ptr ) or raise Sodium::CryptoError, 'failed to generate an authenticator' end end |
#verify(message, authenticator) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sodium/one_time_auth.rb', line 27 def verify(, authenticator) = self.class.() authenticator = self.class._authenticator(authenticator) self.implementation.nacl_verify( authenticator.to_ptr, .to_ptr, .bytesize, @key .to_ptr ) end |