Class: JWT::JWA::HmacRbNaClFixed
- Inherits:
-
Object
- Object
- JWT::JWA::HmacRbNaClFixed
- Includes:
- SigningAlgorithm
- Defined in:
- lib/jwt/jwa/hmac_rbnacl_fixed.rb
Overview
Implementation of the HMAC family of algorithms (using RbNaCl prior to a certain version)
Instance Attribute Summary
Attributes included from SigningAlgorithm
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(alg, hmac) ⇒ HmacRbNaClFixed
constructor
A new instance of HmacRbNaClFixed.
- #sign(data:, signing_key:) ⇒ Object
- #verify(data:, signature:, verification_key:) ⇒ Object
Methods included from SigningAlgorithm
#header, included, #raise_sign_error!, #raise_verify_error!, #valid_alg?
Constructor Details
permalink #initialize(alg, hmac) ⇒ HmacRbNaClFixed
Returns a new instance of HmacRbNaClFixed.
13 14 15 16 |
# File 'lib/jwt/jwa/hmac_rbnacl_fixed.rb', line 13 def initialize(alg, hmac) @alg = alg @hmac = hmac end |
Class Method Details
permalink .from_algorithm(algorithm) ⇒ Object
[View source] [View on GitHub]
9 10 11 |
# File 'lib/jwt/jwa/hmac_rbnacl_fixed.rb', line 9 def self.from_algorithm(algorithm) new(algorithm, ::RbNaCl::HMAC.const_get(algorithm.upcase.gsub('HS', 'SHA'))) end |
Instance Method Details
permalink #sign(data:, signing_key:) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/jwt/jwa/hmac_rbnacl_fixed.rb', line 18 def sign(data:, signing_key:) signing_key ||= '' Deprecations.warning("The use of the algorithm #{alg} is deprecated and will be removed in the next major version of ruby-jwt") raise JWT::DecodeError, 'HMAC key expected to be a String' unless signing_key.is_a?(String) hmac.auth(padded_key_bytes(signing_key, hmac.key_bytes), data.encode('binary')) end |
permalink #verify(data:, signature:, verification_key:) ⇒ Object
[View source] [View on GitHub]
26 27 28 29 30 31 32 33 34 |
# File 'lib/jwt/jwa/hmac_rbnacl_fixed.rb', line 26 def verify(data:, signature:, verification_key:) verification_key ||= '' Deprecations.warning("The use of the algorithm #{alg} is deprecated and will be removed in the next major version of ruby-jwt") raise JWT::DecodeError, 'HMAC key expected to be a String' unless verification_key.is_a?(String) hmac.verify(padded_key_bytes(verification_key, hmac.key_bytes), signature.encode('binary'), data.encode('binary')) rescue ::RbNaCl::BadAuthenticatorError, ::RbNaCl::LengthError false end |