Sha256: 95e346c9a4b22827df7305e30abb0665be29b2b7bcd0f1bc019bd2ff289c7152

Contents?: true

Size: 903 Bytes

Versions: 17

Compression:

Stored size: 903 Bytes

Contents

require 'openssl'
require 'tempfile'

module Heirloom
  module Cipher
    class File

      def initialize(args)
        @config = args[:config]
        @aes = OpenSSL::Cipher::AES256.new(:CBC)
      end

      def encrypt_file(args)
        file   = args[:file]
        secret = args[:secret]
        output = Tempfile.new('archive.tar.gz.enc')
        iv     = @aes.random_iv

        @aes.encrypt
        @aes.iv = iv
        @aes.key = Digest::SHA256.hexdigest secret

        # Need to refactor to be less complex
        # Additionally tests to do fully cover logic
        ::File.open(output,'w') do |enc|
          enc << iv
          ::File.open(file) do |f|
            loop do
              r = f.read(4096)
              break unless r
              enc << @aes.update(r)
            end
          end
          enc << @aes.final
        end
        output.path
      end

    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
heirloom-0.8.3 lib/heirloom/cipher/file.rb
heirloom-0.8.2 lib/heirloom/cipher/file.rb
heirloom-0.8.1 lib/heirloom/cipher/file.rb
heirloom-0.8.0 lib/heirloom/cipher/file.rb
heirloom-0.7.4 lib/heirloom/cipher/file.rb
heirloom-0.7.3 lib/heirloom/cipher/file.rb
heirloom-0.7.3rc2 lib/heirloom/cipher/file.rb
heirloom-0.7.3rc1 lib/heirloom/cipher/file.rb
heirloom-0.7.2 lib/heirloom/cipher/file.rb
heirloom-0.7.2rc2 lib/heirloom/cipher/file.rb
heirloom-0.7.2rc1 lib/heirloom/cipher/file.rb
heirloom-0.7.1 lib/heirloom/cipher/file.rb
heirloom-0.7.0 lib/heirloom/cipher/file.rb
heirloom-0.7.0rc1 lib/heirloom/cipher/file.rb
heirloom-0.6.1 lib/heirloom/cipher/file.rb
heirloom-0.6.0rc1 lib/heirloom/cipher/file.rb
heirloom-0.5.0rc4 lib/heirloom/cipher/file.rb