Module: Origami::Encryption::EncryptedStream

Includes:
EncryptedObject
Defined in:
lib/origami/encryption.rb

Overview

Module for encrypted Stream.

Instance Attribute Summary

Attributes included from EncryptedObject

#decrypted

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EncryptedObject

#post_build

Class Method Details

.extended(obj) ⇒ Object



441
442
443
# File 'lib/origami/encryption.rb', line 441

def self.extended(obj)
    obj.decrypted = false
end

Instance Method Details

#decrypt!Object



469
470
471
472
473
474
475
476
477
478
479
# File 'lib/origami/encryption.rb', line 469

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!Object



445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/origami/encryption.rb', line 445

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