Class: FunWith::Passwords::FileStore
- Inherits:
-
Object
- Object
- FunWith::Passwords::FileStore
- Defined in:
- lib/fun_with/passwords/file_store.rb
Overview
The FileStore knows only where to save itself, and how to encrypt and decrypt the file. The contents of a file are a mystery for Keychain to deal with
Constant Summary collapse
- DEFAULT_DIR =
XDG['CONFIG'].fwf_filepath.join("fun_with_passwords")
- DEFAULT_EXT =
"aes256.dat"
- DEFAULT_FILENAME =
"password_store"
Instance Attribute Summary collapse
-
#key_chain ⇒ Object
Returns the value of attribute key_chain.
-
#password_file ⇒ Object
Returns the value of attribute password_file.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filename = nil) ⇒ FileStore
constructor
if the key is nil, waits until a password is requested or added to decrypt password file.
-
#save(yaml, master_key) ⇒ Object
def initialize_key_chain_if_needed( keychain_keys, master_key ) unless @key_chain @key_chain = Keychain.new( :keys => keychain_keys, :master_key => master_key ) @key_chain.file_store = self end end.
-
#unlock(master_key) ⇒ Object
sends back a Keychain that knows where its store is.
Constructor Details
#initialize(filename = nil) ⇒ FileStore
if the key is nil, waits until a password is requested or added to decrypt password file
19 20 21 22 |
# File 'lib/fun_with/passwords/file_store.rb', line 19 def initialize( filename = nil ) @password_file = ( filename ) @password_file.touch end |
Instance Attribute Details
#key_chain ⇒ Object
Returns the value of attribute key_chain.
12 13 14 |
# File 'lib/fun_with/passwords/file_store.rb', line 12 def key_chain @key_chain end |
#password_file ⇒ Object
Returns the value of attribute password_file.
12 13 14 |
# File 'lib/fun_with/passwords/file_store.rb', line 12 def password_file @password_file end |
Class Method Details
.default_file ⇒ Object
14 15 16 |
# File 'lib/fun_with/passwords/file_store.rb', line 14 def self.default_file DEFAULT_DIR.join( "#{DEFAULT_FILENAME}.#{DEFAULT_EXT}" ) end |
Instance Method Details
#save(yaml, master_key) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/fun_with/passwords/file_store.rb', line 40 def save( yaml, master_key ) = Crypt.encrypt( yaml, master_key ) @password_file.write( ) true rescue Exception => e false end |
#unlock(master_key) ⇒ Object
sends back a Keychain that knows where its store is
25 26 27 28 29 30 31 |
# File 'lib/fun_with/passwords/file_store.rb', line 25 def unlock( master_key ) if @password_file.file? && !@password_file.empty? YAML.load( Crypt.decrypt( @password_file.read, master_key ) ) else {} end end |