Sha256: 3421187500825334b38c6d4fb407c154f425766125c4ff8c87057c9f8435a246

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

module Xmlenc
  module Builder
    class EncryptedKey
      include Xmlenc::Builder::ComplexTypes::EncryptedType

      ALGORITHMS = {
          'http://www.w3.org/2001/04/xmlenc#rsa-1_5'        => Algorithms::RSA15,
          'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p' => Algorithms::RsaOaepMgf1p
      }

      tag "EncryptedKey"
      namespace "xenc"

      has_one :reference_list, Xmlenc::Builder::ReferenceList, :xpath => "./"

      attr_accessor :data

      def encrypt(key, data = nil)
        encryptor = algorithm.new(key)
        encrypted = encryptor.encrypt(data || self.data)
        cipher_data.cipher_value = Base64.encode64(encrypted)
      end

      def add_data_reference(data_id)
        self.reference_list ||= ReferenceList.new
        self.reference_list.add_data_reference(data_id)
      end

      private

      def algorithm
        algorithm = encryption_method.algorithm
        ALGORITHMS[algorithm] ||
            raise(UnsupportedError.new("Unsupported encryption method #{algorithm}"))
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
xmlenc-0.3.0 lib/xmlenc/builder/encrypted_key.rb
xmlenc-0.2.1 lib/xmlenc/builder/encrypted_key.rb
xmlenc-0.2.0 lib/xmlenc/builder/encrypted_key.rb
xmlenc-0.1.7 lib/xmlenc/builder/encrypted_key.rb
xmlenc-0.1.6 lib/xmlenc/builder/encrypted_key.rb