Commit e6bbb54
Changed files (10)
lib/xml/kit/key_info/key_value.rb
@@ -0,0 +1,17 @@
+module Xml
+ module Kit
+ class KeyInfo
+ # An implementation of the RSAKeyValue element.
+ # https://www.w3.org/TR/xmldsig-core1/#sec-KeyValue
+ #
+ # @since 0.3.0
+ class KeyValue
+ include Templatable
+
+ def rsa
+ @rsa ||= RSAKeyValue.new
+ end
+ end
+ end
+ end
+end
lib/xml/kit/key_info/retrieval_method.rb
@@ -0,0 +1,17 @@
+module Xml
+ module Kit
+ class KeyInfo
+ # An implementation of the RSAKeyValue element.
+ # https://www.w3.org/TR/xmldsig-core1/#sec-RetrievalMethod
+ #
+ # @since 0.3.0
+ class RetrievalMethod
+ attr_accessor :uri, :type
+
+ def initialize
+ @type = "#{Namespaces::XMLENC}EncryptedKey"
+ end
+ end
+ end
+ end
+end
lib/xml/kit/key_info/rsa_key_value.rb
@@ -0,0 +1,13 @@
+module Xml
+ module Kit
+ class KeyInfo
+ # An implementation of the RSAKeyValue element.
+ # https://www.w3.org/TR/xmldsig-core1/#sec-RSAKeyValue
+ #
+ # @since 0.3.0
+ class RSAKeyValue
+ attr_accessor :modulus, :exponent
+ end
+ end
+ end
+end
lib/xml/kit/decryption.rb
@@ -15,6 +15,7 @@ module Xml
# Decrypts an EncryptedData section of an XML document.
#
# @param data [Hash] the XML document converted to a [Hash] using Hash.from_xml.
+ # @deprecated Use {#decrypt_hash} instead of this
def decrypt(data)
::Xml::Kit.deprecate(
'decrypt is deprecated. Use decrypt_xml or decrypt_hash instead.'
lib/xml/kit/encrypted_data.rb
@@ -2,6 +2,10 @@
module Xml
module Kit
+ # An implementation of the EncryptedKey element.
+ # https://www.w3.org/TR/xmlenc-core1/#sec-EncryptedData
+ #
+ # @since 0.3.0
class EncryptedData
attr_reader :key_info
attr_reader :symmetric_cipher
lib/xml/kit/encrypted_key.rb
@@ -4,6 +4,10 @@ require 'xml/kit/templatable'
module Xml
module Kit
+ # An implementation of the EncryptedKey element.
+ # https://www.w3.org/TR/xmlenc-core1/#sec-EncryptedKey
+ #
+ # @since 0.3.0
class EncryptedKey
include ::Xml::Kit::Templatable
attr_reader :id
lib/xml/kit/encryption.rb
@@ -2,6 +2,7 @@
module Xml
module Kit
+ # @deprecated Use {#Xml::Kit::EncryptedData} class instead of this
class Encryption < EncryptedData
attr_reader :asymmetric_algorithm
attr_reader :symmetric_algorithm
lib/xml/kit/key_info.rb
@@ -1,28 +1,16 @@
# frozen_string_literal: true
+require 'xml/kit/key_info/key_value'
+require 'xml/kit/key_info/retrieval_method'
+require 'xml/kit/key_info/rsa_key_value'
+
module Xml
module Kit
+ # An implementation of the KeyInfo element.
+ # https://www.w3.org/TR/xmldsig-core1/#sec-KeyInfo
+ #
+ # @since 0.3.0
class KeyInfo
- class RSAKeyValue
- attr_accessor :modulus, :exponent
- end
-
- class KeyValue
- include Templatable
-
- def rsa
- @rsa ||= RSAKeyValue.new
- end
- end
-
- class RetrievalMethod
- attr_accessor :uri, :type
-
- def initialize
- @type = "#{Namespaces::XMLENC}EncryptedKey"
- end
- end
-
include Templatable
attr_accessor :key_name
attr_accessor :x509_data
lib/xml/kit/signature.rb
@@ -2,6 +2,10 @@
module Xml
module Kit
+ # An implementation of the Signature element.
+ # https://www.w3.org/TR/xmldsig-core1/#sec-Signature
+ #
+ # @since 0.1.0
class Signature
SIGNATURE_METHODS = {
SHA1: 'http://www.w3.org/2000/09/xmldsig#rsa-sha1',
lib/xml/kit/templatable.rb
@@ -23,8 +23,9 @@ module Xml
pretty ? Nokogiri::XML(result).to_xml(indent: 2) : result
end
- # Generates an EncryptedKey section. https://www.w3.org/TR/xmlenc-core1/#sec-EncryptedKey
+ # Generates an {#Xml::Kit::EncryptedKey} section. https://www.w3.org/TR/xmlenc-core1/#sec-EncryptedKey
#
+ # @since 0.3.0
# @param xml [Builder::XmlMarkup] the xml builder instance
# @param id [String] the id of EncryptedKey element
def encrypt_key_for(xml:, id:)
@@ -35,6 +36,7 @@ module Xml
).to_xml(xml: xml)
end
+ # @deprecated Use {#encrypt_data_for} instead of this
def encryption_for(*args, &block)
::Xml::Kit.deprecate(
'encryption_for is deprecated. Use encrypt_data_for instead.'
@@ -42,8 +44,9 @@ module Xml
encrypt_data_for(*args, &block)
end
- # Generates an EncryptedData section. https://www.w3.org/TR/xmlenc-core1/#sec-EncryptedData
+ # Generates an {#Xml::Kit::EncryptedData} section. https://www.w3.org/TR/xmlenc-core1/#sec-EncryptedData
#
+ # @since 0.3.0
# @param xml [Builder::XmlMarkup] the xml builder instance
# @param key_info [Xml::Kit::KeyInfo] the key info to render in the EncryptedData
def encrypt_data_for(xml:, key_info: nil)
@@ -59,6 +62,10 @@ module Xml
).to_xml(xml: xml)
end
+ # Provides a default RSA asymmetric cipher. Can be overridden to provide custom ciphers.
+ #
+ # @abstract
+ # @since 0.3.0
def asymmetric_cipher(algorithm: Crypto::RsaCipher::ALGORITHM)
@asymmetric_cipher ||= Crypto.cipher_for(
algorithm,
@@ -66,6 +73,10 @@ module Xml
)
end
+ # Provides a default aes256-cbc symmetric cipher. Can be overridden to provide custom ciphers.
+ #
+ # @abstract
+ # @since 0.3.0
def symmetric_cipher
@symmetric_cipher ||= Crypto::SymmetricCipher.new
end