class OpenSSL::SignatureAlgorithm::ECDSA
Constants
- ACCEPTED_PARAMETERS
- BYTE_LENGTH
Attributes
curve[R]
hash_function[R]
Public Class Methods
new(curve: nil, hash_function: nil)
click to toggle source
# File lib/openssl/signature_algorithm/ecdsa.rb, line 54 def initialize(curve: nil, hash_function: nil) @curve, @hash_function = pick_parameters(curve, hash_function) end
Public Instance Methods
compatible_verify_key?(key)
click to toggle source
Calls superclass method
OpenSSL::SignatureAlgorithm::Base#compatible_verify_key?
# File lib/openssl/signature_algorithm/ecdsa.rb, line 62 def compatible_verify_key?(key) super && key.respond_to?(:group) && key.group.curve_name == curve end
generate_signing_key()
click to toggle source
# File lib/openssl/signature_algorithm/ecdsa.rb, line 58 def generate_signing_key @signing_key = SigningKey.new(curve) end
Private Instance Methods
formatted_signature(signature)
click to toggle source
Borrowed from jwt rubygem. github.com/jwt/ruby-jwt/blob/7a6a3f1dbaff806993156d1dff9c217bb2523ff8/lib/jwt/security_utils.rb#L34-L39
Hopefully this will be provided by openssl rubygem in the future.
# File lib/openssl/signature_algorithm/ecdsa.rb, line 72 def formatted_signature(signature) n = (verify_key_length.to_f / BYTE_LENGTH).ceil if signature.size == n * 2 r = signature[0..(n - 1)] s = signature[n..-1] OpenSSL::ASN1::Sequence.new([r, s].map { |int| OpenSSL::ASN1::Integer.new(OpenSSL::BN.new(int, 2)) }).to_der else signature end end
pick_parameters(curve, hash_function)
click to toggle source
# File lib/openssl/signature_algorithm/ecdsa.rb, line 89 def pick_parameters(curve, hash_function) parameters = ACCEPTED_PARAMETERS.detect do |params| if curve if hash_function params[:curve] == curve && params[:hash_function] == hash_function else params[:curve] == curve end elsif hash_function params[:hash_function] == hash_function else true end end if parameters [parameters[:curve], parameters[:hash_function]] else raise(OpenSSL::SignatureAlgorithm::UnsupportedParameterError, "Unsupported algorithm parameters") end end
verify_key_length()
click to toggle source
# File lib/openssl/signature_algorithm/ecdsa.rb, line 85 def verify_key_length verify_key.group.degree end