edge badge
Namespace
Methods
C
G
K
N
R
W
Constants
CIPHER = "aes-128-gcm"
 
Attributes
[R] content_path
[R] env_key
[R] key_path
Class Public methods
generate_key()
# File activesupport/lib/active_support/encrypted_file.rb, line 23
def self.generate_key
  SecureRandom.hex(ActiveSupport::MessageEncryptor.key_len(CIPHER))
end
new(content_path:, key_path:, env_key:)
# File activesupport/lib/active_support/encrypted_file.rb, line 30
def initialize(content_path,, key_path,, env_key))
  @content_path, @key_path = Pathname.new(content_path), Pathname.new(key_path)
  @env_key = env_key
end
Instance Public methods
change(&block)
# File activesupport/lib/active_support/encrypted_file.rb, line 52
def change(&block)
  writing read, &block
end
key()
# File activesupport/lib/active_support/encrypted_file.rb, line 35
def key
  read_env_key || read_key_file || handle_missing_key
end
read()
# File activesupport/lib/active_support/encrypted_file.rb, line 39
def read
  if content_path.exist?
    decrypt content_path.binread
  else
    raise MissingContentError, content_path
  end
end
write(contents)
# File activesupport/lib/active_support/encrypted_file.rb, line 47
def write(contents)
  IO.binwrite "#{content_path}.tmp", encrypt(contents)
  FileUtils.mv "#{content_path}.tmp", content_path
end