Module: Lich::Common::CLI::CLIConversion
- Defined in:
- documented/common/cli/cli_conversion.rb
Class Method Summary collapse
-
.conversion_needed?(data_dir) ⇒ Boolean
Determines if conversion is needed based on the presence of entry.dat and absence of entry.yaml.
-
.convert(data_dir, encryption_mode) ⇒ Boolean
Converts the entry.dat file to the new format based on the specified encryption mode.
-
.print_conversion_help_message ⇒ void
Prints a help message to the standard output regarding the conversion of saved entries.
Class Method Details
.conversion_needed?(data_dir) ⇒ Boolean
Determines if conversion is needed based on the presence of entry.dat and absence of entry.yaml.
13 14 15 16 17 18 |
# File 'documented/common/cli/cli_conversion.rb', line 13 def self.conversion_needed?(data_dir) dat_file = File.join(data_dir, 'entry.dat') yaml_file = Lich::Common::Authentication::EntryStore.yaml_file_path(data_dir) File.exist?(dat_file) && !File.exist?(yaml_file) end |
.convert(data_dir, encryption_mode) ⇒ Boolean
Converts the entry.dat file to the new format based on the specified encryption mode.
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 53 54 55 56 57 |
# File 'documented/common/cli/cli_conversion.rb', line 26 def self.convert(data_dir, encryption_mode) # Normalize encryption_mode to symbol if string is passed mode = encryption_mode.to_sym # Validate preconditions dat_file = File.join(data_dir, 'entry.dat') yaml_file = Lich::Common::Authentication::EntryStore.yaml_file_path(data_dir) unless File.exist?(dat_file) Lich.log "error: entry.dat not found at #{dat_file}" return false end if File.exist?(yaml_file) Lich.log "error: entry.yaml already exists at #{yaml_file}" return false end # Delegate to EntryStore for the actual conversion # For enhanced mode, migrate_from_legacy will prompt user to create master password result = Lich::Common::Authentication::EntryStore.migrate_from_legacy(data_dir, encryption_mode: mode) unless result Lich.log "error: EntryStore.migrate_from_legacy returned false" end result rescue StandardError => e Lich.log "error: Conversion failed: #{e.class}: #{e.}" Lich.log "error: Backtrace: #{e.backtrace.join("\n ")}" false end |
.print_conversion_help_message ⇒ void
This method returns an undefined value.
Prints a help message to the standard output regarding the conversion of saved entries.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'documented/common/cli/cli_conversion.rb', line 62 def self. lich_script = File.join(LICH_DIR, 'lich.rbw') $stdout.puts "\n" + '=' * 80 $stdout.puts "Saved entries conversion required" $stdout.puts '=' * 80 $stdout.puts "\nYour login entries need to be converted to the new format." $stdout.puts "\nRun one of these commands:\n\n" $stdout.puts "For no encryption (least secure):" $stdout.puts " ruby #{lich_script} --convert-entries plaintext\n\n" $stdout.puts "For account-based encryption (standard):" $stdout.puts " ruby #{lich_script} --convert-entries standard\n\n" $stdout.puts "For master-password encryption (recommended):" $stdout.puts " ruby #{lich_script} --convert-entries enhanced\n\n" $stdout.puts '=' * 80 + "\n" end |