Sha256: ba2fdc18ba4f4dc3cb0c815c0806dcbeeadbc87b271909575c33a323a93354d4

Contents?: true

Size: 849 Bytes

Versions: 10

Compression:

Stored size: 849 Bytes

Contents

require 'sym'
require 'sym/application'
require 'sym/app/args'

module Sym
  # This class provides a convenience wrapper for opening and reading
  # encrypted files as they were regular files, and then possibly writing
  # changes to them later.

  class EncryptedFile

    include Sym

    attr_reader :application, :file, :key_id, :key_type, :app_args

    def initialize(file:, key_id:, key_type:)
      @file        = file
      @key_id      = key_id
      @key_type    = key_type.to_sym
      @app_args    = { file: file, key_type => key_id, decrypt: true }
      @application = Sym::Application.new(self.app_args)
    end

    def read
      @content = application.execute! unless @content
      @content
    end

    def write
      Sym::Application.new(file: file, key_type => key_id, encrypt: true, output: file).execute
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sym-2.3.0 lib/sym/encrypted_file.rb
sym-2.2.1 lib/sym/encrypted_file.rb
sym-2.2.0 lib/sym/encrypted_file.rb
sym-2.1.2 lib/sym/encrypted_file.rb
sym-2.1.1 lib/sym/encrypted_file.rb
sym-2.1.0 lib/sym/encrypted_file.rb
sym-2.0.3 lib/sym/encrypted_file.rb
sym-2.0.2 lib/sym/encrypted_file.rb
sym-2.0.1 lib/sym/encrypted_file.rb
sym-2.0.0 lib/sym/encrypted_file.rb