Class: OpenSSL::SignatureAlgorithm::RSA

Inherits:
Base
  • Object
show all
Defined in:
lib/openssl/signature_algorithm/rsa.rb

Direct Known Subclasses

RSAPKCS1, RSAPSS

Defined Under Namespace

Classes: SigningKey, VerifyKey

Constant Summary collapse

ACCEPTED_HASH_FUNCTIONS =
["SHA256", "SHA384", "SHA512"].freeze
DEFAULT_KEY_SIZE =
2048

Instance Attribute Summary collapse

Attributes inherited from Base

#signing_key, #verify_key

Instance Method Summary collapse

Methods inherited from Base

#compatible_verify_key?, #sign, #verify

Constructor Details

#initialize(hash_function: self.class::ACCEPTED_HASH_FUNCTIONS.first) ⇒ RSA

Returns a new instance of RSA.



39
40
41
42
43
44
45
# File 'lib/openssl/signature_algorithm/rsa.rb', line 39

def initialize(hash_function: self.class::ACCEPTED_HASH_FUNCTIONS.first)
  if self.class::ACCEPTED_HASH_FUNCTIONS.include?(hash_function)
    @hash_function = hash_function
  else
    raise(OpenSSL::SignatureAlgorithm::UnsupportedParameterError, "Unsupported hash function '#{hash_function}'")
  end
end

Instance Attribute Details

#hash_functionObject (readonly)

Returns the value of attribute hash_function.



37
38
39
# File 'lib/openssl/signature_algorithm/rsa.rb', line 37

def hash_function
  @hash_function
end

Instance Method Details

#generate_signing_key(size: DEFAULT_KEY_SIZE) ⇒ Object



47
48
49
# File 'lib/openssl/signature_algorithm/rsa.rb', line 47

def generate_signing_key(size: DEFAULT_KEY_SIZE)
  @signing_key = SigningKey.new(size)
end