bin/krypton in krypton-0.1.6 vs bin/krypton in krypton-0.1.7

- old
+ new

@@ -26,10 +26,14 @@ opts.on('-r', '--raw', 'Set the input and output type to the raw bytes, if available (Default: false)') do options[:raw] = true end + opts.on('-u', '--urlsafe', 'Make output data URL safe (base64)') do + options[:urlsafe] = true + end + opts.on('--verbose', 'Run verbosely') do $verbose = true end opts.on('-v', '--version', 'Show the krypton version and exit') do @@ -45,10 +49,11 @@ opts.separator Paint["\nTasks: ", '#95a5a6'] end.parse!(ARGV) +# Tasks loop while (opt = ARGV.shift) do case opt # AESING when 'encrypt' @@ -66,10 +71,11 @@ else puts "#{ARGV[ARGV.length - 2] + ' => '}#{Paint[result.strip, '#2ecc71']}" end exit 0 + # HASHING when 'hash' data = ARGV[ARGV.length - 1] || gets @@ -79,12 +85,14 @@ puts result.strip else puts "#{data + ' => '}#{Paint[result.strip, '#2ecc71']}" end exit 0 + when 'uuid' puts Paint[SecureRandom.uuid, '#2ecc71'] + when 'totp' if ARGV.length == 2 puts "You need a secret to generate a totp." exit 1 else @@ -94,9 +102,28 @@ else puts "#{secret + ' => ' + Paint[ROTP::TOTP.new(secret).now,'#2ecc71']}" end exit 0 end + + when 'b64e' + data = ARGV[ARGV.length - 1] || gets + if options[:std] + puts Krypton::B64.encode(data, options[:urlsafe]) + else + puts "#{data + ' => ' + Paint[Krypton::B64.encode(data, options[:urlsafe]),'#2ecc71']}" + end + exit 0 + + when 'b64d' + data = ARGV[ARGV.length - 1] || gets + if options[:std] + puts Krypton::B64.decode(data, options[:urlsafe]) + else + puts "#{data + ' => ' + Paint[Krypton::B64.decode(data, options[:urlsafe]),'#2ecc71']}" + end + exit 0 + else puts "#{opt} is not a valid action!" exit 1 end end