class Xmlenc::Builder::EncryptedData

Constants

ALGORITHMS
TYPES

Public Class Methods

new(*args) click to toggle source
# File lib/xmlenc/builder/encrypted_data.rb, line 29
def initialize(*args)
  options = args.extract_options!
  if options.key?(:id)
    self.id = options.delete(:id)
  else
    self.id = "_#{SecureRandom.hex(5)}"
  end
  super(*(args << options))
end

Public Instance Methods

encrypt(data, key_options = {}) click to toggle source
# File lib/xmlenc/builder/encrypted_data.rb, line 39
def encrypt(data, key_options = {})
  encryptor = algorithm.setup
  encrypted = encryptor.encrypt(data, :node => encryption_method)
  cipher_data.cipher_value = Base64.encode64(encrypted)

  key_params = { :data => encryptor.key }

  encrypted_key = EncryptedKey.new(key_params.merge(key_options))
  encrypted_key.add_data_reference(id)

  if key_options[:carried_key_name].present?
    encrypted_key.carried_key_name = key_options[:carried_key_name]
  end

  encrypted_key
end
set_key_name(key_name) click to toggle source
# File lib/xmlenc/builder/encrypted_data.rb, line 63
def set_key_name(key_name)
  if key_name
    self.key_info ||= KeyInfo.new
    self.key_info.key_name = key_name
  end
end
set_key_retrieval_method(retrieval_method) click to toggle source
# File lib/xmlenc/builder/encrypted_data.rb, line 56
def set_key_retrieval_method(retrieval_method)
  if retrieval_method
    self.key_info ||= KeyInfo.new
    self.key_info.retrieval_method = retrieval_method
  end
end
type() click to toggle source
# File lib/xmlenc/builder/encrypted_data.rb, line 25
def type
  'http://www.w3.org/2001/04/xmlenc#Element'
end

Private Instance Methods

algorithm() click to toggle source
# File lib/xmlenc/builder/encrypted_data.rb, line 72
def algorithm
  algorithm = encryption_method.algorithm
  ALGORITHMS[algorithm] ||
      raise(UnsupportedError.new("Unsupported encryption method #{algorithm}"))
end