-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Minisign | ||
# A module that invokes RbNaCl with user-focused actionable error messages. | ||
module NaCl | ||
def self.assert_libsodium_dependency_met! | ||
return if RbNaCl.const_defined?(:PasswordHash) | ||
|
||
raise Minisign::LibSodiumDependencyError, 'libsodium is not installed!' | ||
end | ||
|
||
module Hash | ||
# see RbNaCl::Hash::Blake2b | ||
module Blake2b | ||
def self.digest(*args) | ||
NaCl.assert_libsodium_dependency_met! | ||
RbNaCl::Hash::Blake2b.digest(*args) | ||
end | ||
end | ||
end | ||
|
||
# see RbNaCl::PasswordHash | ||
module PasswordHash | ||
def self.scrypt(*args) | ||
NaCl.assert_libsodium_dependency_met! | ||
RbNaCl::PasswordHash.scrypt(*args) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Minisign::NaCl do | ||
it 'raises LibSodiumDependencyError if libsodium not installed' do | ||
hash = RbNaCl.send(:remove_const, :Hash) | ||
password_hash = RbNaCl.send(:remove_const, :PasswordHash) | ||
expect do | ||
Minisign::NaCl::Hash::Blake2b.digest('message', { digest_size: 32 }) | ||
end.to raise_error(Minisign::LibSodiumDependencyError) | ||
RbNaCl.const_set(:Hash, hash) | ||
RbNaCl.const_set(:PasswordHash, password_hash) | ||
end | ||
end |