Class: Xmldsig::Signature
- Inherits:
-
Object
- Object
- Xmldsig::Signature
- Defined in:
- lib/xmldsig/signature.rb
Instance Attribute Summary collapse
-
#signature ⇒ Object
Returns the value of attribute signature.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(signature, id_attr = nil, referenced_documents = {}) ⇒ Signature
constructor
A new instance of Signature.
- #references ⇒ Object
- #sign(private_key = nil, &block) ⇒ Object
- #signature_value ⇒ Object
- #signed? ⇒ Boolean
- #signed_info ⇒ Object
- #unsigned? ⇒ Boolean
- #valid?(certificate = nil, schema = nil, &block) ⇒ Boolean
Constructor Details
#initialize(signature, id_attr = nil, referenced_documents = {}) ⇒ Signature
Returns a new instance of Signature.
5 6 7 8 9 |
# File 'lib/xmldsig/signature.rb', line 5 def initialize(signature, id_attr = nil, referenced_documents = {}) @signature = signature @id_attr = id_attr @referenced_documents = referenced_documents end |
Instance Attribute Details
#signature ⇒ Object
Returns the value of attribute signature.
3 4 5 |
# File 'lib/xmldsig/signature.rb', line 3 def signature @signature end |
Instance Method Details
#errors ⇒ Object
17 18 19 |
# File 'lib/xmldsig/signature.rb', line 17 def errors references.flat_map(&:errors) + @errors end |
#references ⇒ Object
11 12 13 14 15 |
# File 'lib/xmldsig/signature.rb', line 11 def references @references ||= signature.xpath("descendant::ds:Reference", NAMESPACES).map do |node| Reference.new(node, @id_attr, @referenced_documents) end end |
#sign(private_key = nil, &block) ⇒ Object
21 22 23 24 |
# File 'lib/xmldsig/signature.rb', line 21 def sign(private_key = nil, &block) references.each { |reference| reference.sign } self.signature_value = calculate_signature_value(private_key, &block) end |
#signature_value ⇒ Object
30 31 32 |
# File 'lib/xmldsig/signature.rb', line 30 def signature_value Base64.decode64 signature.at_xpath("descendant::ds:SignatureValue", NAMESPACES).content end |
#signed? ⇒ Boolean
43 44 45 |
# File 'lib/xmldsig/signature.rb', line 43 def signed? !unsigned? end |
#signed_info ⇒ Object
26 27 28 |
# File 'lib/xmldsig/signature.rb', line 26 def signed_info signature.at_xpath("descendant::ds:SignedInfo", NAMESPACES) end |
#unsigned? ⇒ Boolean
47 48 49 |
# File 'lib/xmldsig/signature.rb', line 47 def unsigned? self.signature_value.to_s.empty? end |
#valid?(certificate = nil, schema = nil, &block) ⇒ Boolean
34 35 36 37 38 39 40 41 |
# File 'lib/xmldsig/signature.rb', line 34 def valid?(certificate = nil, schema = nil, &block) @errors = [] references.each { |r| r.errors = [] } validate_schema(schema) validate_digest_values validate_signature_value(certificate, &block) errors.empty? end |