Class: Sandal::Sig::RS
- Inherits:
-
Object
- Object
- Sandal::Sig::RS
- Defined in:
- lib/sandal/sig/rs.rb
Overview
Base implementation of the RSA-SHA family of signature algorithms.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The JWA name of the algorithm.
Instance Method Summary collapse
-
#initialize(name, sha_size, key) ⇒ RS
constructor
Creates a new instance; it’s probably easier to use one of the subclass constructors.
-
#sign(payload) ⇒ String
Signs a payload and returns the signature.
-
#valid?(signature, payload) ⇒ Boolean
Validates a payload signature and returns whether the signature matches.
Constructor Details
#initialize(name, sha_size, key) ⇒ RS
Creates a new instance; it’s probably easier to use one of the subclass constructors.
19 20 21 22 23 |
# File 'lib/sandal/sig/rs.rb', line 19 def initialize(name, sha_size, key) @name = name @digest = OpenSSL::Digest.new("sha#{sha_size}") @key = key end |
Instance Attribute Details
#name ⇒ Object (readonly)
The JWA name of the algorithm.
10 11 12 |
# File 'lib/sandal/sig/rs.rb', line 10 def name @name end |
Instance Method Details
#sign(payload) ⇒ String
Signs a payload and returns the signature.
29 30 31 |
# File 'lib/sandal/sig/rs.rb', line 29 def sign(payload) @key.sign(@digest, payload) end |
#valid?(signature, payload) ⇒ Boolean
Validates a payload signature and returns whether the signature matches.
38 39 40 41 42 |
# File 'lib/sandal/sig/rs.rb', line 38 def valid?(signature, payload) @key.verify(@digest, signature, payload) rescue OpenSSL::PKey::PKeyError # happens in jruby if the signature is invalid false end |