Skip to content

Commit

Permalink
add change password functionality (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl authored Feb 11, 2024
1 parent 73bbd98 commit 7758d76
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bin/minisign
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ op = OptionParser.new do |opts|
opts.on('-G') do |g|
options[:G] = g
end
opts.on('-R') do |r|
options[:R] = r
end
opts.on('-C') do |c|
options[:C] = c
end
opts.on('-W') do |w|
options[:W] = w
end
opts.on('-f') do |f|
options[:f] = f
end
Expand All @@ -35,3 +44,4 @@ end

Minisign::CLI.generate(options) if options[:G]
Minisign::CLI.recreate(options) if options[:R]
Minisign::CLI.recreate(options) if options[:C]
10 changes: 10 additions & 0 deletions lib/minisign/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,15 @@ def self.recreate(options)
end
File.write(public_key, private_key.public_key)
end

def self.change_password(options)
options[:s] || "#{Dir.home}/.minisign/minisign.key"
print 'Password: '
private_key = Minisign::PrivateKey.new(File.read(options[:s]), prompt)
print 'New Password: '
new_password = options[:W] ? nil : prompt
private_key.change_password! new_password
File.write(options[:s], private_key)
end
end
end
28 changes: 28 additions & 0 deletions spec/minisign/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,32 @@
expect(new_public_key).to eq(existing_public_key)
end
end

describe '.change_password' do
before do
FileUtils.cp('test/minisign.key', 'test/generated/minisign.key')
@options = {
s: 'test/generated/minisign.key'
}
@old_password = 'password'
end
it 'changes the password for the private key' do
new_password = SecureRandom.uuid
allow(Minisign::CLI).to receive(:prompt).and_return(@old_password, new_password)
Minisign::CLI.change_password(@options)
expect do
Minisign::PrivateKey.new(File.read(@options[:s]), new_password)
end.not_to raise_error
end

it 'changes the password for the private key without a password'

it 'removes the password for the private key' do
allow(Minisign::CLI).to receive(:prompt).and_return(@old_password)
Minisign::CLI.change_password(@options.merge({ W: true }))
expect do
Minisign::PrivateKey.new(File.read(@options[:s]))
end.not_to raise_error
end
end
end

0 comments on commit 7758d76

Please sign in to comment.