bin/krypton in krypton-0.1.2 vs bin/krypton in krypton-0.1.3
- old
+ new
@@ -14,10 +14,14 @@
options[:raw] = false
OptionParser.new do |opts|
opts.banner = "A command-line tool to encrypt and decrypt data in multiple formats.\n\nUsage: #{File.basename($PROGRAM_NAME)} [options] [task] \"message\" \"key\"\nKrypton version: #{Paint[VERSION, '#2ecc71']}"
opts.separator Paint["\nGlobal Options: ", '#95a5a6']
+ opts.on('-s', '--std', 'Print output suitable for piping.') do
+ options[:std] = true
+ end
+
opts.on('-o OUTFILE', '--outfile OUTFILE', String, 'A file to save the output in') do |v|
options[:outfile] = v
end
opts.on('-r', '--raw', 'Set the input and output type to the raw bytes, if available (Default: false)') do
@@ -46,19 +50,31 @@
while (opt = ARGV.shift) do
case opt
when 'encrypt'
#puts Krypton::AESCrypt.encrypt(ARGV[ARGV.length - 2], ARGV[ARGV.length - 1], options[:outfile]) if options[:raw]
result = Base64.encode64(Krypton::AESCrypt.encrypt(ARGV[ARGV.length - 2], ARGV[ARGV.length - 1], options[:outfile]))
- puts "#{ARGV[ARGV.length - 2] + ' => '}#{Paint[result.strip, '#2ecc71']}"
+ if options[:std]
+ puts result.strip
+ else
+ puts "#{ARGV[ARGV.length - 2] + ' => '}#{Paint[result.strip, '#2ecc71']}"
+ end
exit 0
when 'decrypt'
#puts Krypton::AESCrypt.decrypt(ARGV[ARGV.length - 2], ARGV[ARGV.length - 1], options[:outfile]) if options[:raw]
result = Krypton::AESCrypt.decrypt(Base64.decode64(ARGV[ARGV.length - 2]), ARGV[ARGV.length - 1], options[:outfile])
- puts "#{ARGV[ARGV.length - 2] + ' => '}#{Paint[result.strip, '#2ecc71']}"
+ if options[:std]
+ puts result.strip
+ else
+ puts "#{ARGV[ARGV.length - 2] + ' => '}#{Paint[result.strip, '#2ecc71']}"
+ end
exit 0
when 'hash'
result = Krypton::SHA.hash(ARGV[ARGV.length - 1], options[:raw])
- puts "#{ARGV[ARGV.length - 1] + ' => '}#{Paint[result.strip, '#2ecc71']}"
+ if options[:std]
+ puts result.strip
+ else
+ puts "#{ARGV[ARGV.length - 1] + ' => '}#{Paint[result.strip, '#2ecc71']}"
+ end
exit 0
else
puts "#{opt} is not a valid action!"
exit 1
end