class HealthCards::PublicKey
A key used for verifying JWS
Public Class Methods
from_json(json)
click to toggle source
# File lib/health_cards/public_key.rb, line 6 def self.from_json(json) # TODO end
Public Instance Methods
verify(payload, signature)
click to toggle source
# File lib/health_cards/public_key.rb, line 10 def verify(payload, signature) @key.verify(OpenSSL::Digest.new('SHA256'), raw_to_asn1(signature, self), payload) end
Private Instance Methods
raw_to_asn1(signature, key)
click to toggle source
Convert the raw signature into the ASN.1 Representation
Adapted from ruby-jwt and json-jwt gems. More info here: github.com/nov/json-jwt/issues/21 github.com/jwt/ruby-jwt/pull/87 github.com/jwt/ruby-jwt/issues/84
# File lib/health_cards/public_key.rb, line 22 def raw_to_asn1(signature, key) byte_size = (key.group.degree + 7) / 8 sig_bytes = signature[0..(byte_size - 1)] sig_char = signature[byte_size..] || '' OpenSSL::ASN1::Sequence.new([sig_bytes, sig_char].map do |int| OpenSSL::ASN1::Integer.new(OpenSSL::BN.new(int, 2)) end).to_der end