Commit 609b4b4

mokha <mo@mokhan.ca>
2019-01-21 23:56:46
extract encrypt_key_for helper method
1 parent 849ec1b
Changed files (3)
lib
spec
fixtures
support
lib/xml/kit/templatable.rb
@@ -23,6 +23,10 @@ module Xml
         pretty ? Nokogiri::XML(result).to_xml(indent: 2) : result
       end
 
+      def encrypt_key_for(xml: , id: , public_key: , key: )
+        ::Xml::Kit::EncryptedKey.new(id: id, public_key: public_key, key: key).to_xml(xml: xml)
+      end
+
       def encryption_for(xml:, key_info: nil, &block)
         ::Xml::Kit.deprecate('encryption_for is deprecated. Use encrypt_data_for instead.')
         encrypt_data_for(xml: xml, key_info: key_info, &block)
spec/fixtures/soap.builder
@@ -3,28 +3,7 @@ xml.instruct!
 xml.Envelope xmlns: "http://schemas.xmlsoap.org/soap/envelope/" do
   xml.Header do
     xml.Security mustUnderstand: '1' do
-      xml.EncryptedKey xmlns: 'http://www.w3.org/2001/04/xmlenc#', Id: key_id do
-        xml.EncryptionMethod Algorithm: 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p' do
-          xml.KeyInfo xmlns: '' do
-            xml.SecurityTokenReference do
-              xml.x509Data do
-                xml.x509IssuerSerial do
-                  xml.x509IssuerName ''
-                  xml.x509IssuerNumber ''
-                end
-              end
-            end
-          end
-          xml.CipherData do
-            xml.CipherValue ''
-          end
-          xml.ReferenceList do
-            xml.DataReference URI: ''
-          end
-        end
-      end
-      #encrypt_key_for(xml: xml, id: body_key_info.uri) do |xml|
-      #end
+      encrypt_key_for(xml: xml, id: body_key_info.uri, public_key: encryption_key_pair.public_key, key: SecureRandom.hex(32))
       xml.BinarySecurityToken ''
     end
   end
spec/support/soap.rb
@@ -3,12 +3,11 @@
 class Soap
   include ::Xml::Kit::Templatable
 
-  attr_reader :id, :signing_key_pair, :encryption_key_pair
+  attr_reader :id, :encryption_key_pair
   attr_accessor :template_path
 
   def initialize
     @id = ::Xml::Kit::Id.generate
-    @signing_key_pair = ::Xml::Kit::KeyPair.generate(use: :signing)
     @embed_signature = false
     @encrypt = true
     @encryption_key_pair = ::Xml::Kit::KeyPair.generate(use: :encryption)