class COSE::Algorithm::SignatureAlgorithm
Public Instance Methods
compatible_key?(key)
click to toggle source
# File lib/cose/algorithm/signature_algorithm.rb, line 14 def compatible_key?(key) valid_key?(key) && to_pkey(key) rescue COSE::Error false end
verify(key, signature, verification_data)
click to toggle source
# File lib/cose/algorithm/signature_algorithm.rb, line 9 def verify(key, signature, verification_data) compatible_key?(key) || raise(COSE::Error, "Incompatible key for signature verification") valid_signature?(key, signature, verification_data) || raise(COSE::Error, "Signature verification failed") end
Private Instance Methods
signature_algorithm_class()
click to toggle source
# File lib/cose/algorithm/signature_algorithm.rb, line 48 def signature_algorithm_class raise NotImplementedError end
signature_algorithm_parameters()
click to toggle source
# File lib/cose/algorithm/signature_algorithm.rb, line 33 def signature_algorithm_parameters { hash_function: hash_function } end
to_cose_key(key)
click to toggle source
# File lib/cose/algorithm/signature_algorithm.rb, line 37 def to_cose_key(key) case key when COSE::Key::Base key when OpenSSL::PKey::PKey COSE::Key.from_pkey(key) else raise(COSE::Error, "Don't know how to transform #{key.class} to COSE::Key") end end
to_pkey(_key)
click to toggle source
# File lib/cose/algorithm/signature_algorithm.rb, line 56 def to_pkey(_key) raise NotImplementedError end
valid_key?(_key)
click to toggle source
# File lib/cose/algorithm/signature_algorithm.rb, line 52 def valid_key?(_key) raise NotImplementedError end
valid_signature?(key, signature, verification_data)
click to toggle source
# File lib/cose/algorithm/signature_algorithm.rb, line 22 def valid_signature?(key, signature, verification_data) signature_algorithm = signature_algorithm_class.new(**signature_algorithm_parameters) signature_algorithm.verify_key = to_pkey(key) begin signature_algorithm.verify(signature, verification_data) rescue OpenSSL::SignatureAlgorithm::Error false end end