Module: Origami::Encryption::EncryptedStream

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

Overview

Module for encrypted Stream.

Instance Attribute Summary

Attributes included from EncryptedObject

#algorithm, #decrypted, #encryption_handler, #encryption_key

Instance Method Summary collapse

Methods included from EncryptedObject

extended, #post_build

Instance Method Details

#decrypt!Object



522
523
524
525
526
527
528
529
530
531
# File 'lib/origami/encryption.rb', line 522

def decrypt!
  unless @decrypted
    key = compute_object_key

    self.rawdata = @algorithm.decrypt(key, @rawdata)
    @decrypted = true
  end

  self
end

#encrypt!Object



499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/origami/encryption.rb', line 499

def encrypt!
  if @decrypted
    encode!

    key = compute_object_key

    @rawdata = 
      if @algorithm == ARC4 or @algorithm == Identity
        @algorithm.encrypt(key, self.rawdata)
      else
        iv = Encryption.rand_bytes(AES::BLOCKSIZE)
        @algorithm.encrypt(key, iv, @rawdata)
      end

    @decrypted = false

    @rawdata.freeze
    self.freeze
  end

  self
end