Class: Sigstore::Internal::Key::RSA

Inherits:
Sigstore::Internal::Key show all
Defined in:
lib/sigstore/internal/key.rb

Instance Attribute Summary

Attributes inherited from Sigstore::Internal::Key

#key_id, #key_type, #schema

Instance Method Summary collapse

Methods inherited from Sigstore::Internal::Key

from_key_details, #public_to_der, read, #to_der, #to_pem

Methods included from Loggable

included, #logger

Constructor Details

#initializeRSA

Returns a new instance of RSA.

Raises:

  • (ArgumentError)


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/sigstore/internal/key.rb', line 113

def initialize(...)
  super
  raise ArgumentError, "key_type must be rsa, given #{@key_type}" unless @key_type == "rsa"

  unless @key.is_a?(OpenSSL::PKey::RSA)
    raise ArgumentError, "key must be an OpenSSL::PKey::RSA, given #{@key.inspect}"
  end

  case @schema
  when "rsassa-pss-sha256"
    raise Error::UnsupportedPlatform, "RSA-PSS verification unsupported" unless @key.respond_to?(:verify_pss)
  when "rsa-pkcs1v15-sha256"
    # supported
  else
    raise ArgumentError, "Unsupported schema #{schema}"
  end
end

Instance Method Details

#verify(_algo, signature, data) ⇒ Object



131
132
133
134
135
136
137
138
139
140
# File 'lib/sigstore/internal/key.rb', line 131

def verify(_algo, signature, data)
  case @schema
  when "rsassa-pss-sha256"
    @key.verify_pss("sha256", signature, data, salt_length: :auto, mgf1_hash: "SHA256")
  when "rsa-pkcs1v15-sha256"
    super
  else
    raise ArgumentError, "Unsupported schema #{schema}"
  end
end