Module: Lich::Common::GUI::PasswordManager

Defined in:
documented/common/gui/password_manager.rb

Class Method Summary collapse

Class Method Details

.change_password(entry:, new_password:, account_name: nil, master_password: nil) ⇒ Hash

Changes the password for a given entry based on the specified encryption mode.

Parameters:

  • entry (Hash)

    the entry containing the password and encryption mode

  • new_password (String)

    the new password to set

  • account_name (String, nil) (defaults to: nil)

    optional account name for standard mode

  • master_password (String, nil) (defaults to: nil)

    optional master password for enhanced mode

Returns:

  • (Hash)

    the updated entry with the new password

Raises:

  • (ArgumentError)

    if required parameters are missing for the specified mode

  • (NotImplementedError)

    if the encryption mode is not implemented



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'documented/common/gui/password_manager.rb', line 19

def self.change_password(entry:, new_password:, account_name: nil, master_password: nil)
  mode = entry[:encryption_mode]&.to_sym || :plaintext

  case mode
  when :plaintext
    # Plaintext mode - store password directly
    entry[:password] = new_password
  when :standard
    # Standard mode - encrypt with account name
    raise ArgumentError, 'account_name required for standard mode' if .nil?

    entry[:password] = PasswordCipher.encrypt(
      new_password,
      mode: :standard,
      account_name: 
    )
  when :enhanced
    # Enhanced encryption mode - encrypt with master password
    raise ArgumentError, 'master_password required for enhanced mode' if master_password.nil?

    entry[:password] = PasswordCipher.encrypt(
      new_password,
      mode: :enhanced,
      master_password: master_password
    )
  when :ssh_key
    # Certificate encryption mode - future feature, not yet implemented
    raise NotImplementedError, "#{mode} mode not yet implemented"
  else
    raise ArgumentError, "Unknown encryption mode: #{mode}"
  end

  entry
end

.get_password(entry:, account_name: nil, master_password: nil) ⇒ String

Retrieves the password for a given entry based on the specified encryption mode.

Parameters:

  • entry (Hash)

    the entry containing the encrypted password and encryption mode

  • account_name (String, nil) (defaults to: nil)

    optional account name for standard mode

  • master_password (String, nil) (defaults to: nil)

    optional master password for enhanced mode

Returns:

  • (String)

    the decrypted or plaintext password

Raises:

  • (ArgumentError)

    if required parameters are missing for the specified mode

  • (NotImplementedError)

    if the encryption mode is not implemented



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'documented/common/gui/password_manager.rb', line 62

def self.get_password(entry:, account_name: nil, master_password: nil)
  mode = entry[:encryption_mode]&.to_sym || :plaintext
  encrypted_password = entry[:password]

  case mode
  when :plaintext
    # Plaintext mode - return password directly
    encrypted_password
  when :standard
    # Standard mode - decrypt with account name
    raise ArgumentError, 'account_name required for standard mode' if .nil?

    PasswordCipher.decrypt(
      encrypted_password,
      mode: :standard,
      account_name: 
    )
  when :enhanced
    # Enhanced encryption mode - decrypt with master password
    raise ArgumentError, 'master_password required for enhanced mode' if master_password.nil?

    PasswordCipher.decrypt(
      encrypted_password,
      mode: :enhanced,
      master_password: master_password
    )
  when :ssh_key
    # Certificate encryption mode - future feature, not yet implemented
    raise NotImplementedError, "#{mode} mode not yet implemented"
  else
    raise ArgumentError, "Unknown encryption mode: #{mode}"
  end
end