Class: Xmldsig_fiscalizer::Signature
- Inherits:
-
Object
- Object
- Xmldsig_fiscalizer::Signature
- Defined in:
- lib/xmldsig_fiscalizer/signature.rb
Instance Attribute Summary collapse
-
#signature ⇒ Object
Returns the value of attribute signature.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(signature) ⇒ Signature
constructor
A new instance of Signature.
- #references ⇒ Object
- #sign(private_key = nil, &block) ⇒ Object
- #signature_value ⇒ Object
- #signed_info ⇒ Object
- #valid?(certificate = nil, &block) ⇒ Boolean
Constructor Details
#initialize(signature) ⇒ Signature
Returns a new instance of Signature.
5 6 7 |
# File 'lib/xmldsig_fiscalizer/signature.rb', line 5 def initialize(signature) @signature = signature end |
Instance Attribute Details
#signature ⇒ Object
Returns the value of attribute signature.
3 4 5 |
# File 'lib/xmldsig_fiscalizer/signature.rb', line 3 def signature @signature end |
Instance Method Details
#errors ⇒ Object
15 16 17 |
# File 'lib/xmldsig_fiscalizer/signature.rb', line 15 def errors references.flat_map(&:errors) + @errors end |
#references ⇒ Object
9 10 11 12 13 |
# File 'lib/xmldsig_fiscalizer/signature.rb', line 9 def references @references ||= signature.xpath("descendant::ds:Reference", NAMESPACES).map do |node| Reference.new(node) end end |
#sign(private_key = nil, &block) ⇒ Object
19 20 21 22 |
# File 'lib/xmldsig_fiscalizer/signature.rb', line 19 def sign(private_key = nil, &block) references.each(&:sign) self.signature_value = calculate_signature_value(private_key, &block) end |
#signature_value ⇒ Object
28 29 30 |
# File 'lib/xmldsig_fiscalizer/signature.rb', line 28 def signature_value Base64.decode64 signature.at_xpath("descendant::ds:SignatureValue", NAMESPACES).content end |
#signed_info ⇒ Object
24 25 26 |
# File 'lib/xmldsig_fiscalizer/signature.rb', line 24 def signed_info signature.at_xpath("descendant::ds:SignedInfo", NAMESPACES) end |
#valid?(certificate = nil, &block) ⇒ Boolean
32 33 34 35 36 37 38 |
# File 'lib/xmldsig_fiscalizer/signature.rb', line 32 def valid?(certificate = nil, &block) @errors = [] references.each { |r| r.errors = [] } validate_digest_values validate_signature_value(certificate, &block) errors.empty? end |