Module: Dcc::Signature::Signer

Defined in:
lib/dcc/signature/signer.rb

Overview

Dcc::Signature::Signer wraps an enveloped XMLDSig signature over a DCC document using RSA-SHA-256. Requires the xmldsig gem.

Class Method Summary collapse

Class Method Details

.call(xml_or_dcc, cert_pem:, key_pem:) ⇒ String

Returns the signed XML document.

Parameters:

  • xml_or_dcc (String, Lutaml::Model::Serializable)

    the DCC.

  • cert_pem (String)

    PEM-encoded signing certificate.

  • key_pem (String)

    PEM-encoded private key.

Returns:

  • (String)

    the signed XML document.



13
14
15
16
17
18
19
20
21
# File 'lib/dcc/signature/signer.rb', line 13

def call(xml_or_dcc, cert_pem:, key_pem:)
  ensure_xmldsig!
  xml = xml_or_dcc.is_a?(::String) ? xml_or_dcc : xml_or_dcc.to_xml
  document = Xmldsig::XMLDoc.new(xml)
  document.sign(
    OpenSSL::PKey::RSA.new(key_pem),
    cert_pem,
  ).to_xml
end