Skip to content

Commit

Permalink
support -o (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl authored Feb 13, 2024
1 parent 2c7caf7 commit b626c50
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bin/minisign
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Signal.trap('INT') { exit }

options = {}
op = OptionParser.new do |opts|
boolean_opts = %w[G R C W S V Q f q]
boolean_opts = %w[G R C W S V Q f q o]
argument_opts = %w[t m x s p]
boolean_opts.each do |o|
opts.on("-#{o}") do |boolean|
Expand Down
5 changes: 3 additions & 2 deletions lib/minisign/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def self.usage
puts '-S sign files'
puts '-V verify that a signature is valid for a given file'
puts '-m <file> file to sign/verify'
# TODO: implement
puts '-o combined with -V, output the file content after verification'
puts '-p <pubkey_file> public key file (default: ./minisign.pub)'
puts '-P <pubkey> public key, as a base64 string'
Expand Down Expand Up @@ -126,9 +125,11 @@ def self.verify(options)
options[:p] ||= './minisign.pub'
options[:P] ||= File.read(options[:p])
public_key = Minisign::PublicKey.new(options[:P])
message = File.read(options[:m])
signature = Minisign::Signature.new(File.read(options[:x]))
verification = public_key.verify(signature, File.read(options[:m]))
verification = public_key.verify(signature, message)
return if options[:q]
return puts message if options[:o]

puts options[:Q] ? signature.trusted_comment : verification
end
Expand Down
12 changes: 12 additions & 0 deletions spec/minisign/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,17 @@
Minisign::CLI.verify(options)
end.not_to raise_error
end
it 'outputs the message' do
options = {
p: 'test/minisign.pub',
m: 'test/example.txt',
o: true
}
jedisct1 = "test/generated/minisign -Vom #{options[:m]} -p #{options[:p]}"
ruby = "minisign -Vom #{options[:m]} -p #{options[:p]}"
message = File.read(options[:m])
expect(`#{ruby}`).to eq(message)
expect(`#{ruby}`).to eq(`#{jedisct1}`)
end
end
end

0 comments on commit b626c50

Please sign in to comment.