Class: PasswordProtectedFile
- Inherits:
-
Object
- Object
- PasswordProtectedFile
show all
- Defined in:
- lib/password_protected_file.rb
Defined Under Namespace
Classes: FileNotFoundError, FilenameNotAvailableError, IncorrectPasswordError, InvalidDataError, InvalidFilenameError, InvalidPasswordError, InvalidStringEncodingError, PasswordProtectedFileError
Constant Summary
collapse
- DEFAULT_ITERATIONS =
20_000
- ITERATION_BYTES =
8
- KEY_BYTES =
32
- SALT_BYTES =
16
- IV_BYTES =
16
- HASH_FUNCTION =
::OpenSSL::Digest::SHA256
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.create(file_name, password, data = '') ⇒ Object
20
21
22
23
24
25
|
# File 'lib/password_protected_file.rb', line 20
def self.create(file_name, password, data = '')
__send__(:assert_valid_filename, file_name)
__send__(:assert_file_does_not_exist, file_name)
__send__(:assert_valid_password, password)
new(file_name, password).tap { |o| o.__send__(:create_new, data) }
end
|
.open(file_name, password) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/password_protected_file.rb', line 13
def self.open(file_name, password)
__send__(:assert_valid_filename, file_name)
__send__(:assert_file_exists, file_name)
__send__(:assert_valid_password, password)
new(file_name, password).tap { |o| o.__send__(:open_existing) }
end
|
Instance Method Details
#data ⇒ Object
27
28
29
|
# File 'lib/password_protected_file.rb', line 27
def data
@data.clone
end
|
#data=(new_data) ⇒ Object
31
32
33
34
35
|
# File 'lib/password_protected_file.rb', line 31
def data=(new_data)
assert_valid_data(new_data)
@data = new_data.clone
write_file
end
|