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) ⇒ 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, &block) ⇒ Boolean
Constructor Details
#initialize(signature, id_attr = nil) ⇒ Signature
Returns a new instance of Signature.
5 6 7 8 |
# File 'lib/xmldsig/signature.rb', line 5 def initialize(signature, id_attr = nil) @signature = signature @id_attr = id_attr 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
16 17 18 |
# File 'lib/xmldsig/signature.rb', line 16 def errors references.flat_map(&:errors) + @errors end |
#references ⇒ Object
10 11 12 13 14 |
# File 'lib/xmldsig/signature.rb', line 10 def references @references ||= signature.xpath("descendant::ds:Reference", NAMESPACES).map do |node| Reference.new(node, @id_attr) end end |
#sign(private_key = nil, &block) ⇒ Object
20 21 22 23 |
# File 'lib/xmldsig/signature.rb', line 20 def sign(private_key = nil, &block) references.each { |reference| reference.sign } self.signature_value = calculate_signature_value(private_key, &block) end |
#signature_value ⇒ Object
29 30 31 |
# File 'lib/xmldsig/signature.rb', line 29 def signature_value Base64.decode64 signature.at_xpath("descendant::ds:SignatureValue", NAMESPACES).content end |
#signed? ⇒ Boolean
42 43 44 |
# File 'lib/xmldsig/signature.rb', line 42 def signed? !unsigned? end |
#signed_info ⇒ Object
25 26 27 |
# File 'lib/xmldsig/signature.rb', line 25 def signed_info signature.at_xpath("descendant::ds:SignedInfo", NAMESPACES) end |
#unsigned? ⇒ Boolean
46 47 48 |
# File 'lib/xmldsig/signature.rb', line 46 def unsigned? self.signature_value.to_s.empty? end |
#valid?(certificate = nil, &block) ⇒ Boolean
33 34 35 36 37 38 39 40 |
# File 'lib/xmldsig/signature.rb', line 33 def valid?(certificate = nil, &block) @errors = [] references.each { |r| r.errors = [] } validate_schema validate_digest_values validate_signature_value(certificate, &block) errors.empty? end |