Class: ActiveSupport::EncryptedFile
Relationships & Source Files | |
Namespace Children | |
Exceptions:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | activesupport/lib/active_support/encrypted_file.rb |
Constant Summary
-
CIPHER =
# File 'activesupport/lib/active_support/encrypted_file.rb', line 29"aes-128-gcm"
Class Method Summary
Instance Attribute Summary
- #content_path readonly
- #env_key readonly
- #key_path readonly
- #raise_if_missing_key readonly
Instance Method Summary
Constructor Details
.new(content_path:, key_path:, env_key:, raise_if_missing_key:) ⇒ EncryptedFile
# File 'activesupport/lib/active_support/encrypted_file.rb', line 42
def initialize(content_path:, key_path:, env_key:, raise_if_missing_key:) @content_path = Pathname.new(content_path).yield_self { |path| path.symlink? ? path.realpath : path } @key_path = Pathname.new(key_path) @env_key, @raise_if_missing_key = env_key, raise_if_missing_key end
Class Method Details
.generate_key
[ GitHub ]# File 'activesupport/lib/active_support/encrypted_file.rb', line 31
def self.generate_key SecureRandom.hex(ActiveSupport::MessageEncryptor.key_len(CIPHER)) end
Instance Attribute Details
#content_path (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/encrypted_file.rb', line 40
attr_reader :content_path, :key_path, :env_key, :raise_if_missing_key
#env_key (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/encrypted_file.rb', line 40
attr_reader :content_path, :key_path, :env_key, :raise_if_missing_key
#key_path (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/encrypted_file.rb', line 40
attr_reader :content_path, :key_path, :env_key, :raise_if_missing_key
#raise_if_missing_key (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/encrypted_file.rb', line 40
attr_reader :content_path, :key_path, :env_key, :raise_if_missing_key
Instance Method Details
#change(&block)
[ GitHub ]# File 'activesupport/lib/active_support/encrypted_file.rb', line 65
def change(&block) writing read, &block end
#key
[ GitHub ]# File 'activesupport/lib/active_support/encrypted_file.rb', line 48
def key read_env_key || read_key_file || handle_missing_key end
#read
[ GitHub ]# File 'activesupport/lib/active_support/encrypted_file.rb', line 52
def read if !key.nil? && content_path.exist? decrypt content_path.binread else raise MissingContentError, content_path end end
#write(contents)
[ GitHub ]# File 'activesupport/lib/active_support/encrypted_file.rb', line 60
def write(contents) IO.binwrite "#{content_path}.tmp", encrypt(contents) FileUtils.mv "#{content_path}.tmp", content_path end