Commit ab31215

mokha <mo@mokhan.ca>
2019-01-23 01:00:52
remove external key info
1 parent d32af4a
lib/xml/kit/templates/external_key_info.builder
@@ -1,3 +0,0 @@
-xml.KeyInfo xmlns: ::Xml::Kit::Namespaces::XMLDSIG do
-  xml.RetrievalMethod xmlns: ::Xml::Kit::Namespaces::XMLDSIG, URI: uri, Type: type
-end
lib/xml/kit/external_key_info.rb
@@ -1,18 +0,0 @@
-# frozen_string_literal: true
-
-module Xml
-  module Kit
-    class ExternalKeyInfo
-      attr_reader :uri, :type
-
-      def initialize(uri:, type: 'http://www.w3.org/2001/04/xmlenc#EncryptedKey')
-        @uri = uri
-        @type = type
-      end
-
-      def to_xml(xml: ::Builder::XmlMarkup.new)
-        ::Xml::Kit::Template.new(self).to_xml(xml: xml)
-      end
-    end
-  end
-end
lib/xml/kit/key_info.rb
@@ -16,6 +16,10 @@ module Xml
 
     class RetrievalMethod
       attr_accessor :uri, :type
+
+      def initialize
+        @type = 'http://www.w3.org/2001/04/xmlenc#EncryptedKey'
+      end
     end
 
     class KeyInfo
lib/xml/kit.rb
@@ -21,7 +21,6 @@ require 'xml/kit/decryption_error'
 require 'xml/kit/document'
 require 'xml/kit/encrypted_key'
 require 'xml/kit/encryption'
-require 'xml/kit/external_key_info'
 require 'xml/kit/fingerprint'
 require 'xml/kit/id'
 require 'xml/kit/key_info'
spec/fixtures/item-extracted-key.builder
@@ -2,7 +2,9 @@ xml.instruct!
 xml.Item ID: id, xmlns: 'https://www.example.org/item#' do
   signature_for reference_id: id, xml: xml
   xml.Encrypted xmlns: 'https://www.example.org/item#' do
-    encrypt_data_for(xml: xml, key_info: ::Xml::Kit::ExternalKeyInfo.new(uri: "#EK")) do |xml|
+    key_info = ::Xml::Kit::KeyInfo.new
+    key_info.retrieval_method.uri = "#EK"
+    encrypt_data_for(xml: xml, key_info: key_info) do |xml|
       xml.EncryptMe do
         xml.Secret "secret"
       end
spec/fixtures/soap.builder
@@ -3,7 +3,7 @@ xml.instruct!
 xml.Envelope xmlns: "http://schemas.xmlsoap.org/soap/envelope/" do
   xml.Header do
     xml.Security mustUnderstand: '1' do
-      encrypt_key_for(xml: xml, id: body_key_info.uri, public_key: encryption_key_pair.public_key, key: SecureRandom.hex(32))
+      encrypt_key_for(xml: xml, id: key_id, public_key: encryption_key_pair.public_key, key: SecureRandom.hex(32))
       xml.BinarySecurityToken ''
     end
   end
spec/support/soap.rb
@@ -20,6 +20,8 @@ class Soap
   end
 
   def body_key_info
-    ::Xml::Kit::ExternalKeyInfo.new(uri: key_id)
+    x = ::Xml::Kit::KeyInfo.new
+    x.retrieval_method.uri = key_id
+    x
   end
 end
spec/xml/kit/external_key_info_spec.rb
@@ -1,16 +0,0 @@
-RSpec.describe Xml::Kit::ExternalKeyInfo do
-  describe '#to_xml' do
-    subject { described_class.new(uri: uri, type: type) }
-
-    let(:uri) { '#EK' }
-    let(:type) { 'http://www.w3.org/2001/04/xmlenc#EncryptedKey' }
-    let(:result) { Hash.from_xml(subject.to_xml) }
-
-    specify { expect(result['KeyInfo']).to be_present }
-    specify { expect(result['KeyInfo']['RetrievalMethod']).to be_present }
-    specify { expect(result['KeyInfo']['RetrievalMethod']['xmlns']).to eql(::Xml::Kit::Namespaces::XMLDSIG) }
-    specify { expect(result['KeyInfo']['RetrievalMethod']['URI']).to eql(uri) }
-    specify { expect(result['KeyInfo']['RetrievalMethod']['Type']).to eql(type) }
-    specify { expect(result['KeyInfo']['EncryptedKey']).to be_nil }
-  end
-end