class Acme::Client::JWK::Base

def initialize

Returns nothing.

Initialize a new JWK.
def initialize
  raise NotImplementedError
end

def jwa_alg

Returns a String.

The name of the algorithm as needed for the `alg` member of a JWS object.
def jwa_alg
  raise NotImplementedError
end

def jws(header: {}, payload:)

Returns a JSON String.

payload - A Hash of payload data.
header - A Hash of extra header fields to include.

Generate a JWS JSON web signature.
def jws(header: {}, payload:)
  header = jws_header(header)
  encoded_header = Acme::Client::Util.urlsafe_base64(header.to_json)
  encoded_payload = Acme::Client::Util.urlsafe_base64(payload.nil? ? '' : payload.to_json)
  signature_data = "#{encoded_header}.#{encoded_payload}"
  signature = sign(signature_data)
  encoded_signature = Acme::Client::Util.urlsafe_base64(signature)
  {
    protected: encoded_header,
    payload: encoded_payload,
    signature: encoded_signature
  }.to_json
end

def jws_header(header)

Returns a Hash.

typ: - Value for the `typ` field. Default 'JWT'.

Header fields for a JSON web signature.
def jws_header(header)
  jws = {
    typ: 'JWT',
    alg: jwa_alg
  }.merge(header)
  jws[:jwk] = to_h if header[:kid].nil?
  jws
end

def sign(message)

rubocop:disable Lint/UnusedMethodArgument
Returns a String signature.

message - A String message to sign.

Sign a message with the private key.
def sign(message)
  raise NotImplementedError
end

def thumbprint

Returns a String.

JWK thumbprint as used for key authorization.
def thumbprint
  Acme::Client::Util.urlsafe_base64(THUMBPRINT_DIGEST.digest(to_json))
end

def to_h

Returns a Hash.

Get this JWK as a Hash for JSON serialization.
def to_h
  raise NotImplementedError
end

def to_json

Returns a JSON string.

Serialize this JWK as JSON.
def to_json
  to_h.to_json
end