class Origami::Encryption::EncryptionDictionary


Common class for encryption dictionaries.

def cipher_from_crypt_filter_method(name)


Converts a crypt filter method identifier to its cipher class.
def cipher_from_crypt_filter_method(name)
    case name.to_sym
    when :None then Encryption::Identity
    when :V2 then Encryption::RC4
    when :AESV2 then Encryption::AES
    when :AESV3
        raise EncryptionNotSupportedError, "AESV3 requires a version 5 handler" if self.V.to_i != 5
        Encryption::AES
    else
         raise EncryptionNotSupportedError, "Unsupported crypt filter method: #{name}"
    end
end

def encryption_cipher(name)


Returns the encryption cipher corresponding to a crypt filter name.
def encryption_cipher(name)
    case self.V.to_i
    when 1, 2
        Encryption::RC4
    when 4, 5
        return Encryption::Identity if name == :Identity
        select_cipher_by_name(name)
    else
        raise EncryptionNotSupportedError, "Unsupported encryption version: #{handler.V}"
    end
end

def select_cipher_by_name(name)


Returns the cipher associated with a crypt filter name.
def select_cipher_by_name(name)
    raise EncryptionError, "Broken CF entry" unless self.CF.is_a?(Dictionary)
    self.CF.select { |key, dict| key == name and dict.is_a?(Dictionary) }
           .map { |_, dict| cipher_from_crypt_filter_method(dict[:CFM] || :None) }
           .first
end

def stream_encryption_cipher


Returns the default stream encryption cipher.
def stream_encryption_cipher
    encryption_cipher(self.StmF || :Identity)
end

def string_encryption_cipher


Returns the default string encryption cipher.
def string_encryption_cipher
    encryption_cipher(self.StrF || :Identity)
end