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



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

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

Instance Method Details

#decrypt!Object



470
471
472
473
474
475
476
477
478
479
480
# 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!Object



446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# 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