Skip to content

Commit

Permalink
test cli sign and verify (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl authored Feb 13, 2024
1 parent f31a834 commit 7995a82
Show file tree
Hide file tree
Showing 3 changed files with 28 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 f]
boolean_opts = %w[G R C W S V Q f q]
argument_opts = %w[t m x s p]
boolean_opts.each do |o|
opts.on("-#{o}") do |boolean|
Expand Down
8 changes: 6 additions & 2 deletions lib/minisign/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,19 @@ def self.sign(options)
File.write(options[:x], signature)
end

# rubocop:disable Metrics/AbcSize
def self.verify(options)
options[:x] ||= "#{options[:m]}.minisig"
options[:p] ||= './minisign.pub'
options[:P] ||= File.read(options[:p])
# TODO: -q / -Q
public_key = Minisign::PublicKey.new(options[:P])
signature = Minisign::Signature.new(File.read(options[:x]))
puts public_key.verify(signature, File.read(options[:m]))
verification = public_key.verify(signature, File.read(options[:m]))
return if options[:q]

puts options[:Q] ? signature.trusted_comment : verification
end
# rubocop:enable Metrics/AbcSize
end
end

Expand Down
21 changes: 21 additions & 0 deletions spec/minisign/e2e_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,25 @@
public_key = File.read("#{path}/#{keyname}.pub").split("\n").pop
expect(output.gsub('+', '')).to match("minisign -Vm <file> -P #{public_key}".gsub('+', ''))
end
it 'signs files' do
path = 'test/generated'
trusted_comment = SecureRandom.uuid
command = "echo 'password' | minisign -Sm #{path}/.keep -s test/minisign.key -t #{trusted_comment}"
`#{command}`
ruby_signature = File.read("#{path}/.keep.minisig")
command = "echo 'password' | #{path}/minisign -Sm #{path}/.keep -s test/minisign.key -t #{trusted_comment}"
`#{command}`
jedisct1_signature = File.read("#{path}/.keep.minisig")
expect(ruby_signature).to eq(jedisct1_signature)
end
it 'verifies files' do
path = 'test/generated'
command = "minisign -Vm #{path}/.keep -p test/minisign.pub"
expect(`#{command}`).to match(/Signature and comment signature verified\nTrusted comment: [a-z0-9-]+/)
command = "minisign -Vm #{path}/.keep -p test/minisign.pub -Q"
expect(`#{command}`).to match(/^[a-z0-9-]+$/)
command = "minisign -Vm #{path}/.keep -p test/minisign.pub -q"
expect(`#{command}`).to eq('')
end
it 'shows an error message when the signature is invalid'
end

0 comments on commit 7995a82

Please sign in to comment.