Class: JWT::JWA::Rsa
- Inherits:
-
Object
- Object
- JWT::JWA::Rsa
- Includes:
- SigningAlgorithm
- Defined in:
- lib/jwt/jwa/rsa.rb
Overview
Implementation of the RSA family of algorithms
Instance Attribute Summary
Attributes included from SigningAlgorithm
Instance Method Summary collapse
-
#initialize(alg) ⇒ Rsa
constructor
A new instance of Rsa.
- #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
#initialize(alg) ⇒ Rsa
Returns a new instance of Rsa.
9 10 11 12 |
# File 'lib/jwt/jwa/rsa.rb', line 9 def initialize(alg) @alg = alg @digest = OpenSSL::Digest.new(alg.sub('RS', 'SHA')) end |
Instance Method Details
#sign(data:, signing_key:) ⇒ Object
14 15 16 17 18 |
# File 'lib/jwt/jwa/rsa.rb', line 14 def sign(data:, signing_key:) raise_sign_error!("The given key is a #{signing_key.class}. It has to be an OpenSSL::PKey::RSA instance") unless signing_key.is_a?(OpenSSL::PKey::RSA) signing_key.sign(digest, data) end |
#verify(data:, signature:, verification_key:) ⇒ Object
20 21 22 23 24 |
# File 'lib/jwt/jwa/rsa.rb', line 20 def verify(data:, signature:, verification_key:) verification_key.verify(digest, signature, data) rescue OpenSSL::PKey::PKeyError raise JWT::VerificationError, 'Signature verification raised' end |