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



437
438
439
# File 'lib/origami/encryption.rb', line 437

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

Instance Method Details

#decrypt!Object



465
466
467
468
469
470
471
472
473
474
475
# File 'lib/origami/encryption.rb', line 465

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



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'lib/origami/encryption.rb', line 441

def encrypt!
  return self unless @decrypted

  encode!

  cipher = get_encryption_cipher
  key = compute_object_key(cipher)

  @encoded_data =
    if (cipher == RC4) || (cipher == Identity)
      cipher.encrypt(key, encoded_data)
    else
      iv = Encryption.rand_bytes(AES::BLOCKSIZE)
      cipher.encrypt(key, iv, @encoded_data)
    end

  @decrypted = false

  @encoded_data.freeze
  freeze

  self
end