Class: RbNaCl::Auth
- Inherits:
-
Object
- Object
- RbNaCl::Auth
- Defined in:
- lib/rbnacl/auth.rb
Overview
Secret Key Authenticators
These provide a means of verifying the integrity of a message, but only with the knowledge of a shared key. This can be a preshared key, or one that is derived through some cryptographic protocol.
Direct Known Subclasses
Constant Summary collapse
- KEYBYTES =
Number of bytes in a valid key
0
- BYTES =
Number of bytes in a valid authenticator
0
Class Method Summary collapse
-
.auth(key, message) ⇒ String
Compute authenticator for message.
-
.key_bytes ⇒ Integer
The number of key bytes for this Auth class.
-
.tag_bytes ⇒ Integer
The number bytes in the tag or authenticator from this Auth class.
-
.verify(key, authenticator, message) ⇒ Boolean
Verifies the given authenticator with the message.
Instance Method Summary collapse
-
#auth(message) ⇒ String
Compute authenticator for message.
-
#initialize(key) ⇒ Auth
constructor
A new authenticator, ready for auth and verification.
-
#key_bytes ⇒ Integer
The number of key bytes for this Auth instance.
-
#primitive ⇒ Symbol
The crypto primitive for this authenticator instance.
-
#tag_bytes ⇒ Integer
The number of bytes in the tag or authenticator for this Auth instance.
-
#verify(authenticator, message) ⇒ Boolean
Verifies the given authenticator with the message.
Constructor Details
#initialize(key) ⇒ Auth
A new authenticator, ready for auth and verification
22 23 24 |
# File 'lib/rbnacl/auth.rb', line 22 def initialize(key) @key = Util.check_string(key, key_bytes, "#{self.class} key") end |
Class Method Details
.auth(key, message) ⇒ String
Compute authenticator for message
32 33 34 |
# File 'lib/rbnacl/auth.rb', line 32 def self.auth(key, ) new(key).auth() end |
.key_bytes ⇒ Integer
The number of key bytes for this Auth class
87 |
# File 'lib/rbnacl/auth.rb', line 87 def self.key_bytes; self::KEYBYTES; end |
.tag_bytes ⇒ Integer
The number bytes in the tag or authenticator from this Auth class
97 |
# File 'lib/rbnacl/auth.rb', line 97 def self.tag_bytes; self::BYTES; end |
.verify(key, authenticator, message) ⇒ Boolean
Verifies the given authenticator with the message.
46 47 48 |
# File 'lib/rbnacl/auth.rb', line 46 def self.verify(key, authenticator, ) new(key).verify(authenticator, ) end |
Instance Method Details
#auth(message) ⇒ String
Compute authenticator for message
55 56 57 58 59 60 |
# File 'lib/rbnacl/auth.rb', line 55 def auth() authenticator = Util.zeros(tag_bytes) = .to_str compute_authenticator(authenticator, ) authenticator end |
#key_bytes ⇒ Integer
The number of key bytes for this Auth instance
92 |
# File 'lib/rbnacl/auth.rb', line 92 def key_bytes; self.class.key_bytes; end |
#primitive ⇒ Symbol
The crypto primitive for this authenticator instance
80 81 82 |
# File 'lib/rbnacl/auth.rb', line 80 def primitive self.class.primitive end |
#tag_bytes ⇒ Integer
The number of bytes in the tag or authenticator for this Auth instance
102 |
# File 'lib/rbnacl/auth.rb', line 102 def tag_bytes; self.class.tag_bytes; end |
#verify(authenticator, message) ⇒ Boolean
Verifies the given authenticator with the message.
71 72 73 74 75 |
# File 'lib/rbnacl/auth.rb', line 71 def verify(authenticator, ) auth = authenticator.to_s Util.check_length(auth, tag_bytes, "Provided authenticator") (auth, ) || raise(BadAuthenticatorError, "Invalid authenticator provided, message is corrupt") end |