Skip to content

Commit

Permalink
move key id encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl committed Feb 18, 2024
1 parent 440e87f commit 4cf7620
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/minisign/public_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def initialize(str)
# public_key.key_id
# #=> "E86FECED695E8E0"
def key_id
key_id_binary_string.bytes.map { |c| c.to_s(16) }.reverse.join.upcase
hex key_id_binary_string.bytes
end

# Verify a message's signature
Expand Down
12 changes: 4 additions & 8 deletions lib/minisign/signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
module Minisign
# Parse a .minisig file's contents
class Signature
include Utils
# @param str [String] The contents of the .minisig file
# @example
# Minisign::Signature.new(File.read('test/example.txt.minisig'))
def initialize(str)
@lines = str.split("\n")
@decoded = Base64.strict_decode64(@lines[1])
end

# @return [String] the key id
# @example
# Minisign::Signature.new(File.read('test/example.txt.minisig')).key_id
# #=> "E86FECED695E8E0"
def key_id
encoded_signature[2..9].bytes.map { |c| c.to_s(16) }.reverse.join.upcase
hex @decoded[2..9].bytes
end

# @return [String] the trusted comment
Expand All @@ -33,18 +35,12 @@ def trusted_comment_signature

# @return [String] the global signature
def signature
encoded_signature[10..]
@decoded[10..]
end

# @return [String] The signature that can be written to a file
def to_s
"#{@lines.join("\n")}\n"
end

private

def encoded_signature
Base64.decode64(@lines[1])
end
end
end
5 changes: 5 additions & 0 deletions lib/minisign/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def xor(kdf_output, contents)
end
end

# @return [String] bytes as little endian hexadecimal
def hex(bytes)
bytes.map { |c| c.to_s(16) }.reverse.join.upcase
end

# @return [String] the <kdf_output> used to xor the ed25519 keys
def derive_key(password, kdf_salt, kdf_opslimit, kdf_memlimit)
RbNaCl::PasswordHash.scrypt(
Expand Down

0 comments on commit 4cf7620

Please sign in to comment.