Class: OpenSSL::SignatureAlgorithm::Base

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

Direct Known Subclasses

ECDSA, EdDSA, RSA

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#signing_keyObject (readonly)

Returns the value of attribute signing_key.



13
14
15
# File 'lib/openssl/signature_algorithm/base.rb', line 13

def signing_key
  @signing_key
end

#verify_keyObject

Returns the value of attribute verify_key.



13
14
15
# File 'lib/openssl/signature_algorithm/base.rb', line 13

def verify_key
  @verify_key
end

Instance Method Details

#compatible_verify_key?(verify_key) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/openssl/signature_algorithm/base.rb', line 23

def compatible_verify_key?(verify_key)
  verify_key.respond_to?(:verify)
end

#sign(data) ⇒ Object



27
28
29
# File 'lib/openssl/signature_algorithm/base.rb', line 27

def sign(data)
  signing_key.sign(hash_function, data)
end

#verify(signature, verification_data) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/openssl/signature_algorithm/base.rb', line 31

def verify(signature, verification_data)
  formatted_signature =
    if respond_to?(:formatted_signature, true)
      formatted_signature(signature)
    else
      signature
    end

  verify_key.verify(hash_function, formatted_signature, verification_data) ||
    raise(OpenSSL::SignatureAlgorithm::SignatureVerificationError, "Signature verification failed")
end