Skip to content

Commit

Permalink
standardize blake2b implementation (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl authored Feb 4, 2024
1 parent e5af882 commit 0f363f1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 0 additions & 1 deletion lib/minisign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'ed25519'
require 'base64'
require 'openssl'
require 'rbnacl'

require 'minisign/utils'
Expand Down
6 changes: 5 additions & 1 deletion lib/minisign/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
module Minisign
# Helpers used in multiple classes
module Utils
def blake2b256(message)
RbNaCl::Hash::Blake2b.digest(message, { digest_size: 32 })
end

def blake2b512(message)
OpenSSL::Digest.new('BLAKE2b512').digest(message)
RbNaCl::Hash::Blake2b.digest(message, { digest_size: 64 })
end
end
end
3 changes: 1 addition & 2 deletions spec/minisign/private_key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@
@private_key.public_key
].inject(&:+).pack('C*')

computed_checksum = RbNaCl::Hash::Blake2b.digest(key_data, { digest_size: 32 }).bytes

computed_checksum = blake2b256(key_data).bytes
expect(@private_key.checksum).to eq(computed_checksum)
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require 'minisign'

RSpec.configure do |config|
config.include Minisign::Utils
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
Expand Down

0 comments on commit 0f363f1

Please sign in to comment.