Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Make bin/openpgp more useful #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion bin/openpgp
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
#!/usr/bin/env ruby -rubygems
#!/usr/bin/env ruby

require 'rubygems'

$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
require 'openpgp'
require 'optparse'

options = {}
OptionParser.new do |opts|
opts.banner = "Usage: openpgp [options] FILE"

opts.on("-a", "--armor", "ASCII armor") do
options[:armor] = true
end

opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end.parse!


input_file = ARGV.shift

if input_file.nil?
puts "missing FILE"
exit
end

input = File.read(input_file)

if options[:armor]
input = OpenPGP.dearmor(input)
end

msg = OpenPGP::Message.parse(input)

puts "message:"
msg.each do |packet|
puts " #{packet.class.name} size=#{packet.size rescue '?'}"
case packet.class.name
when "OpenPGP::Packet"
puts " ?"
else
puts " #{packet.to_s}"
end
end
9 changes: 9 additions & 0 deletions lib/openpgp/packet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ def write_body(buffer)
buffer.write_byte(algorithm.to_i)
buffer.write_s2k(s2k)
end

def to_s
salt = s2k.salt.unpack('H*')
":symkey enc packet: version #{version}, cipher #{algorithm}, hash #{s2k.algorithm}, salt #{salt}, count #{s2k.count}"
end
end

##
Expand Down Expand Up @@ -349,6 +354,10 @@ def initialize(options = {}, &block)
def write_body(buffer)
buffer.write(data)
end

def to_s
":encrypted data packet:"
end
end

##
Expand Down
16 changes: 8 additions & 8 deletions lib/openpgp/s2k.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def self.parse(input)
end

# @return [Integer]
attr_reader :count
attr_accessor :count

##
# @param [String, #to_s] passphrase
Expand Down Expand Up @@ -221,17 +221,17 @@ def digest_input
end
end

##
# @param [Integer] count
# @return [Integer]
def decode_count(count)
(16 + (count & 15)) << ((count >> 4) + EXPBIAS)
end

protected

EXPBIAS = 6

##
# @param [Integer] count
# @return [Integer]
def decode_count(count)
(16 + (count & 15)) << ((count >> 4) + EXPBIAS)
end

##
# @param [Integer] iterations
# @return [Integer]
Expand Down