Class: JOSE::JWS::ALG_RSA_PKCS1_V1_5
- Inherits:
-
Struct
- Object
- Struct
- JOSE::JWS::ALG_RSA_PKCS1_V1_5
- Defined in:
- lib/jose/jws/alg_rsa_pkcs1_v1_5.rb
Instance Attribute Summary collapse
-
#digest ⇒ Object
Returns the value of attribute digest.
Class Method Summary collapse
-
.from_map(fields) ⇒ Object
JOSE::JWS callbacks.
Instance Method Summary collapse
-
#generate_key(fields) ⇒ Object
JOSE::JWS::ALG callbacks.
- #sign(jwk, message) ⇒ Object
- #to_map(fields) ⇒ Object
- #verify(jwk, message, signature) ⇒ Object
Instance Attribute Details
#digest ⇒ Object
Returns the value of attribute digest
1 2 3 |
# File 'lib/jose/jws/alg_rsa_pkcs1_v1_5.rb', line 1 def digest @digest end |
Class Method Details
.from_map(fields) ⇒ Object
JOSE::JWS callbacks
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/jose/jws/alg_rsa_pkcs1_v1_5.rb', line 5 def self.from_map(fields) case fields['alg'] when 'RS256' return new(OpenSSL::Digest::SHA256), fields.delete('alg') when 'RS384' return new(OpenSSL::Digest::SHA384), fields.delete('alg') when 'RS512' return new(OpenSSL::Digest::SHA512), fields.delete('alg') else raise ArgumentError, "invalid 'alg' for JWS: #{fields['alg'].inspect}" end end |
Instance Method Details
#generate_key(fields) ⇒ Object
JOSE::JWS::ALG callbacks
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/jose/jws/alg_rsa_pkcs1_v1_5.rb', line 33 def generate_key(fields) bitsize, alg = if digest == OpenSSL::Digest::SHA256 [2048, 'RS256'] elsif digest == OpenSSL::Digest::SHA384 [3072, 'RS384'] elsif digest == OpenSSL::Digest::SHA512 [4096, 'RS512'] else raise ArgumentError, "unhandled RSA_PKCS1_v1_5 digest type: #{digest.inspect}" end return JOSE::JWS::ALG.generate_key([:rsa, bitsize], alg) end |
#sign(jwk, message) ⇒ Object
46 47 48 |
# File 'lib/jose/jws/alg_rsa_pkcs1_v1_5.rb', line 46 def sign(jwk, ) return jwk.kty.sign(, digest, padding: :rsa_pkcs1_padding) end |
#to_map(fields) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jose/jws/alg_rsa_pkcs1_v1_5.rb', line 18 def to_map(fields) alg = if digest == OpenSSL::Digest::SHA256 'RS256' elsif digest == OpenSSL::Digest::SHA384 'RS384' elsif digest == OpenSSL::Digest::SHA512 'RS512' else raise ArgumentError, "unhandled RSA_PKCS1_v1_5 digest type: #{digest.inspect}" end return fields.put('alg', alg) end |
#verify(jwk, message, signature) ⇒ Object
50 51 52 |
# File 'lib/jose/jws/alg_rsa_pkcs1_v1_5.rb', line 50 def verify(jwk, , signature) return jwk.kty.verify(, digest, signature, padding: :rsa_pkcs1_padding) end |