Commit 5a6ddff

mokha <mo@mokhan.ca>
2019-01-23 17:03:51
allow block initialization
1 parent ab31215
lib/xml/kit/certificate.rb
@@ -113,12 +113,9 @@ module Xml
       end
 
       def key_info
-        @key_info ||=
-          begin
-            x = KeyInfo.new
-            x.x509_data = x509
-            x
-          end
+        @key_info ||= KeyInfo.new do |x|
+          x.x509_data = x509
+        end
       end
 
       class << self
lib/xml/kit/encryption.rb
@@ -41,10 +41,10 @@ module Xml
       end
 
       def create_key_info_for(public_key, symmetric_cipher, asymmetric_algorithm)
-        key_info = KeyInfo.new
-        key_info.encrypted_key = EncryptedKey.new(public_key: public_key, key: symmetric_cipher.key, algorithm: asymmetric_algorithm)
-        @asymmetric_cipher_value = key_info.encrypted_key.cipher_value
-        key_info
+        KeyInfo.new do |x|
+          x.encrypted_key = EncryptedKey.new(public_key: public_key, key: symmetric_cipher.key, algorithm: asymmetric_algorithm)
+          @asymmetric_cipher_value = x.encrypted_key.cipher_value
+        end
       end
     end
   end
lib/xml/kit/key_info.rb
@@ -28,6 +28,10 @@ module Xml
       attr_accessor :x509_data
       attr_accessor :encrypted_key
 
+      def initialize
+        yield self if block_given?
+      end
+
       def key_value
         @key_value ||= KeyValue.new
       end