Module: Xml::Kit::Templatable
- Included in:
- Certificate, EncryptedKey, KeyInfo, KeyInfo::KeyValue
- Defined in:
- lib/xml/kit/templatable.rb
Instance Attribute Summary collapse
-
#embed_signature ⇒ Object
Can be used to disable embeding a signature.
-
#encrypt ⇒ Object
Used to enable/disable encrypting the document.
-
#encryption_certificate ⇒ Object
The [Xml::Kit::Certificate] that contains the public key to use for encrypting the document.
-
#signing_key_pair ⇒ Object
The [Xml::Kit::KeyPair] to use for generating a signature.
Instance Method Summary collapse
-
#asymmetric_cipher(algorithm: Crypto::RsaCipher::ALGORITHM) ⇒ Object
abstract
Provides a default RSA asymmetric cipher.
-
#encrypt_data_for(xml:, key_info: nil) {|temp| ... } ⇒ Object
Generates an EncryptedData section.
-
#encrypt_key_for(xml:, id:) ⇒ Object
Generates an EncryptedKey section.
-
#encrypt_with(certificate) ⇒ Object
Allows you to specify which public key to use for generating an XML encrypted element.
-
#encryption_for(*args, &block) ⇒ Object
deprecated
Deprecated.
Use #encrypt_data_for instead of this
- #render(model, options) ⇒ Object
-
#sign_with(key_pair) ⇒ Object
Allows you to specify which key pair to use for generating an XML digital signature.
- #signature_for(reference_id:, xml:) ⇒ Object
-
#symmetric_cipher ⇒ Object
abstract
Provides a default aes256-cbc symmetric cipher.
-
#to_xml(xml: ::Builder::XmlMarkup.new, pretty: false) ⇒ Object
Returns the generated XML document with an XML Digital Signature and XML Encryption.
Instance Attribute Details
#embed_signature ⇒ Object
Can be used to disable embeding a signature. By default a signature will be embedded if a signing certificate is available.
9 10 11 |
# File 'lib/xml/kit/templatable.rb', line 9 def @embed_signature end |
#encrypt ⇒ Object
Used to enable/disable encrypting the document.
12 13 14 |
# File 'lib/xml/kit/templatable.rb', line 12 def encrypt @encrypt end |
#encryption_certificate ⇒ Object
The [Xml::Kit::Certificate] that contains the public key to use for encrypting the document.
18 19 20 |
# File 'lib/xml/kit/templatable.rb', line 18 def encryption_certificate @encryption_certificate end |
#signing_key_pair ⇒ Object
The [Xml::Kit::KeyPair] to use for generating a signature.
15 16 17 |
# File 'lib/xml/kit/templatable.rb', line 15 def signing_key_pair @signing_key_pair end |
Instance Method Details
#asymmetric_cipher(algorithm: Crypto::RsaCipher::ALGORITHM) ⇒ Object
Provides a default RSA asymmetric cipher. Can be overridden to provide custom ciphers.
69 70 71 72 73 74 |
# File 'lib/xml/kit/templatable.rb', line 69 def asymmetric_cipher(algorithm: Crypto::RsaCipher::ALGORITHM) @asymmetric_cipher ||= Crypto.cipher_for( algorithm, encryption_certificate.public_key ) end |
#encrypt_data_for(xml:, key_info: nil) {|temp| ... } ⇒ Object
Generates an EncryptedData section. www.w3.org/TR/xmlenc-core1/#sec-EncryptedData
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/xml/kit/templatable.rb', line 52 def encrypt_data_for(xml:, key_info: nil) return yield xml unless encrypt? temp = ::Builder::XmlMarkup.new yield temp ::Xml::Kit::EncryptedData.new( signatures.complete(temp.target!), symmetric_cipher: symmetric_cipher, asymmetric_cipher: asymmetric_cipher, key_info: key_info ).to_xml(xml: xml) end |
#encrypt_key_for(xml:, id:) ⇒ Object
Generates an EncryptedKey section. www.w3.org/TR/xmlenc-core1/#sec-EncryptedKey
31 32 33 34 35 36 37 |
# File 'lib/xml/kit/templatable.rb', line 31 def encrypt_key_for(xml:, id:) ::Xml::Kit::EncryptedKey.new( id: id, asymmetric_cipher: asymmetric_cipher, symmetric_cipher: symmetric_cipher ).to_xml(xml: xml) end |
#encrypt_with(certificate) ⇒ Object
Allows you to specify which public key to use for generating an XML encrypted element.
106 107 108 109 |
# File 'lib/xml/kit/templatable.rb', line 106 def encrypt_with(certificate) self.encrypt = true self.encryption_certificate = certificate end |
#encryption_for(*args, &block) ⇒ Object
Use #encrypt_data_for instead of this
40 41 42 43 44 45 |
# File 'lib/xml/kit/templatable.rb', line 40 def encryption_for(*args, &block) ::Xml::Kit.deprecate( 'encryption_for is deprecated. Use encrypt_data_for instead.' ) encrypt_data_for(*args, &block) end |
#render(model, options) ⇒ Object
84 85 86 |
# File 'lib/xml/kit/templatable.rb', line 84 def render(model, ) ::Xml::Kit::Template.new(model).to_xml() end |
#sign_with(key_pair) ⇒ Object
Allows you to specify which key pair to use for generating an XML digital signature.
97 98 99 100 101 |
# File 'lib/xml/kit/templatable.rb', line 97 def sign_with(key_pair) self.signing_key_pair = key_pair self. = true signatures.sign_with(key_pair) end |
#signature_for(reference_id:, xml:) ⇒ Object
88 89 90 91 92 |
# File 'lib/xml/kit/templatable.rb', line 88 def signature_for(reference_id:, xml:) return unless sign? signatures.build(reference_id).to_xml(xml: xml) end |
#symmetric_cipher ⇒ Object
Provides a default aes256-cbc symmetric cipher. Can be overridden to provide custom ciphers.
80 81 82 |
# File 'lib/xml/kit/templatable.rb', line 80 def symmetric_cipher @symmetric_cipher ||= Crypto::SymmetricCipher.new end |
#to_xml(xml: ::Builder::XmlMarkup.new, pretty: false) ⇒ Object
Returns the generated XML document with an XML Digital Signature and XML Encryption.
21 22 23 24 |
# File 'lib/xml/kit/templatable.rb', line 21 def to_xml(xml: ::Builder::XmlMarkup.new, pretty: false) result = signatures.complete(render(self, xml: xml)) pretty ? Nokogiri::XML(result).to_xml(indent: 2) : result end |