module Origami::Encryption::EncryptedStream
Module for encrypted Stream
.
Public Class Methods
extended(obj)
click to toggle source
# File lib/origami/encryption.rb, line 442 def self.extended(obj) obj.decrypted = false end
Public Instance Methods
decrypt!()
click to toggle source
# File lib/origami/encryption.rb, line 470 def decrypt! return self if @decrypted cipher = get_encryption_cipher key = compute_object_key(cipher) self.encoded_data = cipher.decrypt(key, @encoded_data) @decrypted = true self end
encrypt!()
click to toggle source
# File lib/origami/encryption.rb, line 446 def encrypt! return self unless @decrypted encode! cipher = get_encryption_cipher key = compute_object_key(cipher) @encoded_data = if cipher == RC4 or cipher == Identity cipher.encrypt(key, self.encoded_data) else iv = Encryption.rand_bytes(AES::BLOCKSIZE) cipher.encrypt(key, iv, @encoded_data) end @decrypted = false @encoded_data.freeze self.freeze self end
Private Instance Methods
get_encryption_cipher()
click to toggle source
Get the stream encryption cipher. The cipher used may depend on the presence of a Crypt filter.
# File lib/origami/encryption.rb, line 488 def get_encryption_cipher if self.filters.first == :Crypt params = decode_params.first if params.is_a?(Dictionary) and params.Name.is_a?(Name) crypt_filter = params.Name.value else crypt_filter = :Identity end cipher = self.document.encryption_cipher(crypt_filter) else cipher = self.document.stream_encryption_cipher end raise EncryptionError, "Cannot find stream encryption filter" if cipher.nil? cipher end