Commit c7874cd

mo <mo.khan@gmail.com>
2017-12-30 17:45:51
remove builders namespace.
1 parent 53c26c4
lib/xml/kit/builders/encryption.rb
@@ -1,20 +0,0 @@
-module Xml
-  module Kit
-    module Builders
-      class Encryption
-        attr_reader :public_key
-        attr_reader :key, :iv, :encrypted
-
-        def initialize(raw_xml, public_key)
-          @public_key = public_key
-          cipher = OpenSSL::Cipher.new('AES-256-CBC')
-          cipher.encrypt
-          @key = cipher.random_key
-          @iv = cipher.random_iv
-          @encrypted = cipher.update(raw_xml) + cipher.final
-        end
-      end
-    end
-  end
-end
-
lib/xml/kit/builders/signature.rb
@@ -1,34 +0,0 @@
-module Xml
-  module Kit
-    module Builders
-      class Signature
-        SIGNATURE_METHODS = {
-          SHA1: "http://www.w3.org/2000/09/xmldsig#rsa-sha1",
-          SHA224: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha224",
-          SHA256: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
-          SHA384: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384",
-          SHA512: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512",
-        }.freeze
-        DIGEST_METHODS = {
-          SHA1: "http://www.w3.org/2000/09/xmldsig#SHA1",
-          SHA224: "http://www.w3.org/2001/04/xmldsig-more#sha224",
-          SHA256: "http://www.w3.org/2001/04/xmlenc#sha256",
-          SHA384: "http://www.w3.org/2001/04/xmldsig-more#sha384",
-          SHA512: "http://www.w3.org/2001/04/xmlenc#sha512",
-        }.freeze
-
-        attr_reader :certificate
-        attr_reader :digest_method
-        attr_reader :reference_id
-        attr_reader :signature_method
-
-        def initialize(reference_id, signature_method: :SH256, digest_method: :SHA256, certificate:)
-          @certificate = certificate
-          @digest_method = DIGEST_METHODS[digest_method]
-          @reference_id = reference_id
-          @signature_method = SIGNATURE_METHODS[signature_method]
-        end
-      end
-    end
-  end
-end
lib/xml/kit/encryption.rb
@@ -0,0 +1,17 @@
+module Xml
+  module Kit
+    class Encryption
+      attr_reader :public_key
+      attr_reader :key, :iv, :encrypted
+
+      def initialize(raw_xml, public_key)
+        @public_key = public_key
+        cipher = OpenSSL::Cipher.new('AES-256-CBC')
+        cipher.encrypt
+        @key = cipher.random_key
+        @iv = cipher.random_iv
+        @encrypted = cipher.update(raw_xml) + cipher.final
+      end
+    end
+  end
+end
lib/xml/kit/signature.rb
@@ -0,0 +1,32 @@
+module Xml
+  module Kit
+    class Signature
+      SIGNATURE_METHODS = {
+        SHA1: "http://www.w3.org/2000/09/xmldsig#rsa-sha1",
+        SHA224: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha224",
+        SHA256: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
+        SHA384: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384",
+        SHA512: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512",
+      }.freeze
+      DIGEST_METHODS = {
+        SHA1: "http://www.w3.org/2000/09/xmldsig#SHA1",
+        SHA224: "http://www.w3.org/2001/04/xmldsig-more#sha224",
+        SHA256: "http://www.w3.org/2001/04/xmlenc#sha256",
+        SHA384: "http://www.w3.org/2001/04/xmldsig-more#sha384",
+        SHA512: "http://www.w3.org/2001/04/xmlenc#sha512",
+      }.freeze
+
+      attr_reader :certificate
+      attr_reader :digest_method
+      attr_reader :reference_id
+      attr_reader :signature_method
+
+      def initialize(reference_id, signature_method: :SH256, digest_method: :SHA256, certificate:)
+        @certificate = certificate
+        @digest_method = DIGEST_METHODS[digest_method]
+        @reference_id = reference_id
+        @signature_method = SIGNATURE_METHODS[signature_method]
+      end
+    end
+  end
+end
lib/xml/kit/signatures.rb
@@ -20,7 +20,7 @@ module Xml
       def build(reference_id)
         return nil if key_pair.nil?
 
-        ::Xml::Kit::Builders::Signature.new(
+        ::Xml::Kit::Signature.new(
           reference_id,
           certificate: key_pair.certificate,
           signature_method: signature_method,
lib/xml/kit/templatable.rb
@@ -25,7 +25,7 @@ module Xml
           temp = ::Builder::XmlMarkup.new
           yield temp
           signed_xml = signatures.complete(temp.target!)
-          xml_encryption = ::Xml::Kit::Builders::Encryption.new(
+          xml_encryption = ::Xml::Kit::Encryption.new(
             signed_xml,
             encryption_certificate.public_key
           )
lib/xml/kit.rb
@@ -10,16 +10,16 @@ require "xmldsig"
 
 require "xml/kit/namespaces"
 
-require "xml/kit/builders/encryption"
-require "xml/kit/builders/signature"
 require "xml/kit/certificate"
 require "xml/kit/crypto"
 require "xml/kit/decryption"
 require "xml/kit/document"
+require "xml/kit/encryption"
 require "xml/kit/fingerprint"
 require "xml/kit/id"
 require "xml/kit/key_pair"
 require "xml/kit/self_signed_certificate"
+require "xml/kit/signature"
 require "xml/kit/signatures"
 require "xml/kit/templatable"
 require "xml/kit/template"