Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl committed Feb 19, 2024
1 parent 2f27660 commit ef016a3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
8 changes: 3 additions & 5 deletions bin/minisign
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ rescue OptionParser::InvalidOption
exit 1
end

if options[:G] || options[:R] || options[:G] || options[:S]
unless defined? RbNaCl::Hash
STDERR.puts "Error: libsodium is not installed!"
exit 1
end
if (options[:G] || options[:R] || options[:G] || options[:S]) && !defined? RbNaCl::Hash
warn 'Error: libsodium is not installed!'
exit 1
end

Minisign::CLI.generate(options) if options[:G]
Expand Down
6 changes: 3 additions & 3 deletions lib/minisign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
require 'base64'
require 'openssl'
begin
require 'rbnacl'
rescue LoadError => e
# errors handled when invoked (see Minisign::NaCl)
require 'rbnacl'
rescue LoadError
# errors handled when invoked (see Minisign::NaCl)
end

require 'minisign/cli'
Expand Down
51 changes: 28 additions & 23 deletions lib/minisign/nacl.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
# frozen_string_literal: true

module Minisign
module NaCl
def self.safely
begin
yield
rescue NameError
raise Minisign::LibSodiumDependencyError, 'libsodium is not installed!'
end
end
module Hash
module Blake2b
def self.digest(*args)
NaCl::safely do
RbNaCl::Hash::Blake2b.digest(*args)
end
end
end
# A module that invokes RbNaCl with user-focused actionable error messages.
module NaCl
def self.safely
yield
rescue NameError
raise Minisign::LibSodiumDependencyError, 'libsodium is not installed!'
end

module Hash
# see RbNaCl::Hash::Blake2b
module Blake2b
def self.digest(*args)
NaCl.safely do
RbNaCl::Hash::Blake2b.digest(*args)
end
end
module PasswordHash
def self.scrypt(*args)
NaCl::safely do
RbNaCl::PasswordHash.scrypt(*args)
end
end
end
end

# see RbNaCl::PasswordHash
module PasswordHash
def self.scrypt(*args)
NaCl.safely do
RbNaCl::PasswordHash.scrypt(*args)
end
end
end
end
end
end

0 comments on commit ef016a3

Please sign in to comment.