Namespace

Class

Methods

Constants

CIPHER = "aes-128-gcm"

Attributes

[R] content_path
[R] env_key
[R] key_path
[R] raise_if_missing_key

Class Public methods

generate_key()

📝 Source code
# File activesupport/lib/active_support/encrypted_file.rb, line 24
    def self.generate_key
      SecureRandom.hex(ActiveSupport::MessageEncryptor.key_len(CIPHER))
    end
🔎 See on GitHub

new(content_path:, key_path:, env_key:, raise_if_missing_key:)

📝 Source code
# File activesupport/lib/active_support/encrypted_file.rb, line 31
    def initialize(content_path:, key_path:, env_key:, raise_if_missing_key:)
      @content_path, @key_path = Pathname.new(content_path), Pathname.new(key_path)
      @env_key, @raise_if_missing_key = env_key, raise_if_missing_key
    end
🔎 See on GitHub

Instance Public methods

change(&block)

📝 Source code
# File activesupport/lib/active_support/encrypted_file.rb, line 53
    def change(&block)
      writing read, &block
    end
🔎 See on GitHub

key()

📝 Source code
# File activesupport/lib/active_support/encrypted_file.rb, line 36
    def key
      read_env_key || read_key_file || handle_missing_key
    end
🔎 See on GitHub

read()

📝 Source code
# File activesupport/lib/active_support/encrypted_file.rb, line 40
    def read
      if !key.nil? && content_path.exist?
        decrypt content_path.binread
      else
        raise MissingContentError, content_path
      end
    end
🔎 See on GitHub

write(contents)

📝 Source code
# File activesupport/lib/active_support/encrypted_file.rb, line 48
    def write(contents)
      IO.binwrite "#{content_path}.tmp", encrypt(contents)
      FileUtils.mv "#{content_path}.tmp", content_path
    end
🔎 See on GitHub