Class: Moxml::Signature::Signer

Inherits:
Object
  • Object
show all
Defined in:
lib/moxml/signature/signer.rb

Overview

Reference generation + SignatureValue computation per spec ยง3.1.

Flow:

1. For each Reference in signed_info.references:
 a. Resolve URI (same-document or octet).
 b. Apply each Transform in order.
 c. Compute digest via DigestMethod.
 d. Store base64 digest on Reference#digest_value.
2. Serialize SignedInfo.
3. Canonicalize per CanonicalizationMethod.
4. Sign via SignatureMethod#sign(canonical_octets, key).
5. Set signature.signature_value.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context:, signature:, document:, key:) ⇒ Signer

Returns a new instance of Signer.



20
21
22
23
24
25
# File 'lib/moxml/signature/signer.rb', line 20

def initialize(context:, signature:, document:, key:)
  @context = context
  @signature = signature
  @document = document
  @key = key
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



18
19
20
# File 'lib/moxml/signature/signer.rb', line 18

def context
  @context
end

#documentObject (readonly)

Returns the value of attribute document.



18
19
20
# File 'lib/moxml/signature/signer.rb', line 18

def document
  @document
end

#keyObject (readonly)

Returns the value of attribute key.



18
19
20
# File 'lib/moxml/signature/signer.rb', line 18

def key
  @key
end

#signatureObject (readonly)

Returns the value of attribute signature.



18
19
20
# File 'lib/moxml/signature/signer.rb', line 18

def signature
  @signature
end

Instance Method Details

#signObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/moxml/signature/signer.rb', line 27

def sign
  Algorithms.load_builtins!

  signature.signed_info.references.each do |ref|
    digest = compute_reference_digest(ref)
    ref.digest_value = digest
  end

  signature.signature_value = Model::SignatureValue.new(
    value: compute_signature_value,
  )
  signature
end