summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgeheim.rb63
1 files changed, 34 insertions, 29 deletions
diff --git a/geheim.rb b/geheim.rb
index 9815eda..ce3af4f 100755
--- a/geheim.rb
+++ b/geheim.rb
@@ -70,17 +70,19 @@ module Encryption
super()
if @@key.nil?
@@key = File.read($key_file)
- if ENV['PIN']
- input = ENV['PIN']
- else
- print "PIN: "
- input = $stdin.gets.chomp
- end
- iv = input * 2 + "Hello world" + input * 2
+ pin = read_pin
+ iv = pin * 2 + "Hello world" + pin * 2
@@iv = iv[0..15]
end
end
+ def read_pin
+ return ENV['PIN'] if ENV['PIN']
+ print "PIN: "
+ return STDIN.gets.chomp if %x{uname -o}.include?("Android")
+ STDIN.noecho(&:gets).chomp
+ end
+
def encrypt(plain:)
aes = OpenSSL::Cipher::Cipher.new(@@alg)
aes.encrypt
@@ -182,9 +184,9 @@ class GeheimData < CommitFile
end
end
- def import(source_file:)
- puts "Importing #{source_file} to #{@data_path}"
- @data = File.read(source_file)
+ def reimport_after_export
+ @data = File.read(@exported_path)
+ commit(force: true)
end
def commit(force: false)
@@ -283,14 +285,6 @@ class Geheim
end
end
- def import_recursive(directory:, dest_dir: nil)
- Dir.glob("#{directory}/**/*").each do |source_file|
- next if File.directory?(source_file)
- file = source_file.sub("#{directory}/", "")
- add(description: file, file: source_file, dest_dir: dest_dir)
- end
- end
-
def add(description:)
hash = hash_path(description)
@@ -308,12 +302,12 @@ class Geheim
src_path = file.gsub("//", "/")
dest_path = if dest_dir.nil?
- src_path
- elsif dest_dir.include?(".")
- dest_dir
- else
- "#{dest_dir}/#{File.basename(file)}".gsub("//", "/")
- end
+ src_path
+ elsif dest_dir.include?(".")
+ dest_dir
+ else
+ "#{dest_dir}/#{File.basename(file)}".gsub("//", "/")
+ end
hash = hash_path(dest_path)
@@ -323,6 +317,7 @@ class Geheim
else
puts "Importing #{src_path} -> #{dest_path}"
data = File.read(src_path)
+ shred_file(file: src_path) if action == :newtxt
end
description = dest_path if description.nil?
@@ -333,6 +328,14 @@ class Geheim
index.commit(force: force)
end
+ def import_recursive(directory:, dest_dir: nil)
+ Dir.glob("#{directory}/**/*").each do |source_file|
+ next if File.directory?(source_file)
+ file = source_file.sub("#{directory}/", "")
+ import(description: file, action: :import, file: source_file, dest_dir: dest_dir)
+ end
+ end
+
def rm(search_term:)
indexes = Array.new
walk_indexes(search_term: search_term) do |index|
@@ -385,7 +388,7 @@ class Geheim
file_path
end
- private def edit_exported(file:)
+ private def external_edit(file:)
file_path = "#{$export_dir}/#{file}"
edit_cmd= "#{$edit_cmd} #{file_path}"
puts edit_cmd
@@ -409,7 +412,7 @@ class Geheim
private def hash_path(path_string)
path = Array.new
path_string.gsub("//", "/").split("/").each do |part|
- path << Digest::SHA256.hexdigest(part)
+ path << Digest::SHA256.hexdigest(part)
end
path.join("/")
end
@@ -443,6 +446,11 @@ class CLI
def shell_loop(argv)
loop do
+ if argv.length == 0 or @interactive
+ @interactive = true unless @interactive
+ print "% "
+ argv = $stdin.gets.chomp.split(" ")
+ end
geheim = Geheim.new
action = argv[0]
case action
@@ -487,10 +495,7 @@ class CLI
else
geheim.search(search_term: action)
end
-
break unless @interactive
- print "% "
- argv = $stdin.gets.chomp.split(" ")
end
end
end