Class: JOSE::JWS::ALG_RSA_PSS

Inherits:
Struct
  • Object
show all
Defined in:
lib/jose/jws/alg_rsa_pss.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#digestObject

Returns the value of attribute digest

Returns:

  • (Object)

    the current value of digest



1
2
3
# File 'lib/jose/jws/alg_rsa_pss.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_pss.rb', line 5

def self.from_map(fields)
  case fields['alg']
  when 'PS256'
    return new(OpenSSL::Digest::SHA256), fields.delete('alg')
  when 'PS384'
    return new(OpenSSL::Digest::SHA384), fields.delete('alg')
  when 'PS512'
    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_pss.rb', line 33

def generate_key(fields)
  bitsize, alg = if digest == OpenSSL::Digest::SHA256
    [2048, 'PS256']
  elsif digest == OpenSSL::Digest::SHA384
    [3072, 'PS384']
  elsif digest == OpenSSL::Digest::SHA512
    [4096, 'PS512']
  else
    raise ArgumentError, "unhandled RSA_PSS 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_pss.rb', line 46

def sign(jwk, message)
  return jwk.kty.sign(message, digest, padding: :rsa_pkcs1_pss_padding)
end

#to_map(fields) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jose/jws/alg_rsa_pss.rb', line 18

def to_map(fields)
  alg = if digest == OpenSSL::Digest::SHA256
    'PS256'
  elsif digest == OpenSSL::Digest::SHA384
    'PS384'
  elsif digest == OpenSSL::Digest::SHA512
    'PS512'
  else
    raise ArgumentError, "unhandled RSA_PSS 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_pss.rb', line 50

def verify(jwk, message, signature)
  return jwk.kty.verify(message, digest, signature, padding: :rsa_pkcs1_pss_padding)
end