Commit a21b75b

mo <mo.khan@gmail.com>
2018-02-16 02:24:38
return parent node of decrypted node.
1 parent 0c21193
Changed files (3)
lib/xml/kit/decryption.rb
@@ -40,10 +40,7 @@ module Xml
       def decrypt_node(node)
         return node unless !node.nil? && "EncryptedData" == node.name
 
-        parent = node.parent
-        grand_parent = parent.parent
-        parent.swap(decrypt_xml(node.to_s))
-        grand_parent
+        node.parent.replace(decrypt_xml(node.to_s))[0]
       end
 
       private
lib/xml/kit/encryption.rb
@@ -13,10 +13,10 @@ module Xml
         asymmetric_algorithm: ::Xml::Kit::Crypto::RsaCipher::ALGORITHM
       )
         @symmetric_algorithm = symmetric_algorithm
-        @symmetric_cipher_value = Base64.encode64(symmetric_cipher.encrypt(raw_xml))
+        @symmetric_cipher_value = Base64.encode64(symmetric_cipher.encrypt(raw_xml)).gsub(/\n/, '')
 
         @asymmetric_algorithm = asymmetric_algorithm
-        @asymmetric_cipher_value = Base64.encode64(public_key.public_encrypt(symmetric_cipher.key))
+        @asymmetric_cipher_value = Base64.encode64(public_key.public_encrypt(symmetric_cipher.key)).gsub(/\n/, '')
       end
 
       def to_xml(xml: ::Builder::XmlMarkup.new)
spec/xml/decryption_spec.rb
@@ -140,7 +140,7 @@ RSpec.describe Xml::Kit::Decryption do
     it 'decrypts a nokogiri document' do
       node = document.at_xpath('/Item/Encrypted/xmlenc:EncryptedData', 'xmlenc' => "http://www.w3.org/2001/04/xmlenc#")
       result = subject.decrypt_node(node)
-      expect(result.to_s).to include("EncryptMe")
+      expect(result.name).to eql("EncryptMe")
     end
 
     it 'returns the node when it does not contain an EncryptedData' do