Skip to content

Commit

Permalink
regenerate untrusted comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl committed Feb 7, 2024
1 parent d8aeea4 commit 6f0f5f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/minisign/public_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def initialize(str)
@decoded = Base64.strict_decode64(parts.last)
@public_key = @decoded[10..]
@verify_key = Ed25519::VerifyKey.new(@public_key)
if parts.length == 1
data = Base64.strict_encode64("Ed#{@decoded[2..9]}#{@public_key}")
@untrusted_comment = "minisign public key #{key_id}\n#{data}\n"
else
@untrusted_comment = parts.first.split("untrusted comment: ").last
end
end

# @return [String] the key id
Expand Down Expand Up @@ -44,7 +50,7 @@ def verify(sig, message)

def to_s
data = Base64.strict_encode64("Ed#{@decoded[2..9]}#{@public_key}")
"untrusted comment: minisign public key #{key_id}\n#{data}\n"
"untrusted comment: #{@untrusted_comment}\n#{data}\n"
end

private
Expand Down
4 changes: 4 additions & 0 deletions spec/minisign/public_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@
it 'can be written to a file' do
expect(@pk.to_s).to eq(File.read('test/minisign.pub'))
end
it 'regenerates an untrusted comment if not provided' do
@pk = Minisign::PublicKey.new('RWSmKaOrT6m3TGwjwBovgOmlhSbyBUw3hyhnSOYruHXbJa36xHr8rq2M')
expect(@pk.to_s).to match("minisign public key 4CB7A94FABA329A6")
end
end
2 changes: 1 addition & 1 deletion test/minisign.pub
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
untrusted comment: minisign public key 4CB7A94FABA329A6
untrusted comment: minisign public key 4CB7A94FABA329A6 yay
RWSmKaOrT6m3TGwjwBovgOmlhSbyBUw3hyhnSOYruHXbJa36xHr8rq2M

0 comments on commit 6f0f5f0

Please sign in to comment.