1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-21 10:20:05 +00:00

remove return if useless

This commit is contained in:
Adrien Waksberg 2017-03-28 22:17:52 +02:00
parent 8ed90c2ddc
commit e7fff4bb87
4 changed files with 18 additions and 32 deletions

View file

@ -240,11 +240,7 @@ class Cli
items.sort! { |a,b| a.group.to_s.downcase <=> b.group.to_s.downcase } items.sort! { |a,b| a.group.to_s.downcase <=> b.group.to_s.downcase }
choice = ask(I18n.t('form.select')).to_i choice = ask(I18n.t('form.select')).to_i
if choice >= 1 && choice <= items.length choice >= 1 && choice <= items.length ? items[choice-1] : nil
return items[choice-1]
else
return nil
end
end end
# Copy in clipboard the login and password # Copy in clipboard the login and password
@ -392,7 +388,7 @@ class Cli
options[k.to_sym] = v options[k.to_sym] = v
end end
return options options
end end
# Form to add a new item # Form to add a new item
@ -451,7 +447,7 @@ class Cli
item = get_item(items) item = get_item(items)
confirm = ask("#{I18n.t('form.delete_item.ask')} (y/N) ").to_s confirm = ask("#{I18n.t('form.delete_item.ask')} (y/N) ").to_s
return false unless confirm =~ /^(y|yes|YES|Yes|Y)$/ return unless confirm =~ /^(y|yes|YES|Yes|Y)$/
item.delete item.delete
@mpw.write_data @mpw.write_data

View file

@ -153,7 +153,7 @@ class Config
return true return true
end end
return false false
end end
end end
end end

View file

@ -86,17 +86,17 @@ class Item
end end
def empty? def empty?
return @id.to_s.empty? @id.to_s.empty?
end end
def nil? def nil?
return false false
end end
# Generate an random id # Generate an random id
private private
def generate_id def generate_id
return ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(16).join ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(16).join
end end
end end
end end

View file

@ -168,9 +168,9 @@ class MPW
password = decrypt(@passwords[id]) password = decrypt(@passwords[id])
if /^\$[a-zA-Z0-9]{4,9}::(?<password>.+)$/ =~ password if /^\$[a-zA-Z0-9]{4,9}::(?<password>.+)$/ =~ password
return Regexp.last_match('password') Regexp.last_match('password')
else else
return password password
end end
end end
@ -187,7 +187,7 @@ class MPW
# Return the list of all gpg keys # Return the list of all gpg keys
# rtrn: an array with the gpg keys name # rtrn: an array with the gpg keys name
def list_keys def list_keys
return @keys.keys @keys.keys
end end
# Add a public key # Add a public key
@ -261,7 +261,7 @@ class MPW
result.push(item) result.push(item)
end end
return result result
end end
# Search in some csv data # Search in some csv data
@ -272,7 +272,7 @@ class MPW
return item if item.id == id return item if item.id == id
end end
return nil nil
end end
# Set an opt key # Set an opt key
@ -286,29 +286,20 @@ class MPW
# args: id -> the item id # args: id -> the item id
# key -> the new key # key -> the new key
def get_otp_key(id) def get_otp_key(id)
if @otp_keys.has_key?(id) @otp_keys.has_key?(id) ? decrypt(@otp_keys[id]) : nil
return decrypt(@otp_keys[id])
else
return nil
end
end end
# Get an otp code # Get an otp code
# @args: id -> the item id # @args: id -> the item id
# @rtrn: an otp code # @rtrn: an otp code
def get_otp_code(id) def get_otp_code(id)
unless @otp_keys.has_key?(id) @otp_keys.has_key?(id) ? 0 : ROTP::TOTP.new(decrypt(@otp_keys[id])).now
return 0
else
return ROTP::TOTP.new(decrypt(@otp_keys[id])).now
end
end end
# Get remaining time before expire otp code # Get remaining time before expire otp code
# @rtrn: return time in seconde # @rtrn: return time in seconde
def get_otp_remaining_time def get_otp_remaining_time
return (Time.now.utc.to_i / 30 + 1) * 30 - Time.now.utc.to_i (Time.now.utc.to_i / 30 + 1) * 30 - Time.now.utc.to_i
end end
# Generate a random password # Generate a random password
@ -336,7 +327,7 @@ class MPW
end end
result << chars.sample(length).join result << chars.sample(length).join
return result result
end end
# Decrypt a gpg file # Decrypt a gpg file
@ -347,7 +338,7 @@ class MPW
crypto = GPGME::Crypto.new(armor: true) crypto = GPGME::Crypto.new(armor: true)
return crypto.decrypt(data, password: @gpg_pass).read.force_encoding('utf-8') crypto.decrypt(data, password: @gpg_pass).read.force_encoding('utf-8')
rescue Exception => e rescue Exception => e
raise "#{I18n.t('error.gpg_file.decrypt')}\n#{e}" raise "#{I18n.t('error.gpg_file.decrypt')}\n#{e}"
end end
@ -365,10 +356,9 @@ class MPW
recipients.push(key) recipients.push(key)
end end
return crypto.encrypt(data, recipients: recipients).read crypto.encrypt(data, recipients: recipients).read
rescue Exception => e rescue Exception => e
raise "#{I18n.t('error.gpg_file.encrypt')}\n#{e}" raise "#{I18n.t('error.gpg_file.encrypt')}\n#{e}"
end end
end end
end end