Skip to content

Commit

Permalink
Deprecate rbnacl-libsodium
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Nov 8, 2018
1 parent e4d5811 commit 9a70273
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 28 deletions.
9 changes: 8 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AllCops:
TargetRubyVersion: 2.4
TargetRubyVersion: 2.2
DisplayCopNames: true
Exclude:
- 'vendor/**/*'
Expand Down Expand Up @@ -31,6 +31,13 @@ Metrics/CyclomaticComplexity:
Metrics/PerceivedComplexity:
Max: 15

#
# Naming
#

Naming/UncommunicativeMethodParamName:
Enabled: false

#
# Performance
#
Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ end

group :test do
gem "coveralls", require: false
gem "rbnacl-libsodium", ENV["LIBSODIUM_VERSION"]
gem "rspec"
gem "rubocop", "0.51.0"
gem "rubocop", "0.56.0"
end

group :development, :test do
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "bundler/gem_tasks"

Dir[File.expand_path("../tasks/**/*.rake", __FILE__)].each { |task| load task }
Dir[File.expand_path("tasks/**/*.rake", __dir__)].each { |task| load task }

task default: %w[spec rubocop]
task ci: %w[spec rubocop]
9 changes: 6 additions & 3 deletions lib/rbnacl.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# encoding: binary
# frozen_string_literal: true

if defined?(RBNACL_LIBSODIUM_GEM_LIB_PATH)
raise "rbnacl-libsodium is not supported by rbnacl 6.0+. " \
"Please remove it as a dependency and install libsodium using your system package manager."
end

require "rbnacl/version"
require "rbnacl/sodium"
require "rbnacl/sodium/version"
Expand Down Expand Up @@ -69,9 +74,7 @@ class BadAuthenticatorError < CryptoError; end
# Password hash functions
require "rbnacl/password_hash"
require "rbnacl/password_hash/scrypt"
if RbNaCl::Sodium::Version::ARGON2_SUPPORTED
require "rbnacl/password_hash/argon2"
end
require "rbnacl/password_hash/argon2" if RbNaCl::Sodium::Version::ARGON2_SUPPORTED

# HMAC: SHA256/512 and SHA512256
require "rbnacl/hmac/sha256"
Expand Down
2 changes: 1 addition & 1 deletion lib/rbnacl/boxes/curve25519xsalsa20poly1305.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def nonce_bytes
private

def beforenm
@_key ||= begin
@beforenm ||= begin
key = Util.zeros(BEFORENMBYTES)
success = self.class.box_curve25519xsalsa20poly1305_beforenm(key, @public_key.to_s, @private_key.to_s)
raise CryptoError, "Failed to derive shared key" unless success
Expand Down
6 changes: 1 addition & 5 deletions lib/rbnacl/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ module RbNaCl
# Defines the libsodium init function
module Init
extend FFI::Library
if defined?(RBNACL_LIBSODIUM_GEM_LIB_PATH)
ffi_lib RBNACL_LIBSODIUM_GEM_LIB_PATH
else
ffi_lib "sodium"
end
ffi_lib "sodium"

attach_function :sodium_init, [], :int
end
Expand Down
6 changes: 1 addition & 5 deletions lib/rbnacl/sodium.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ module RbNaCl
module Sodium
def self.extended(klass)
klass.extend FFI::Library
if defined?(RBNACL_LIBSODIUM_GEM_LIB_PATH)
klass.ffi_lib RBNACL_LIBSODIUM_GEM_LIB_PATH
else
klass.ffi_lib "sodium"
end
klass.ffi_lib "sodium"
end

def sodium_type(type = nil)
Expand Down
1 change: 1 addition & 0 deletions lib/rbnacl/test_vectors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,4 @@ module RbNaCl
"a7ea"
}.freeze
end
# rubocop:enable Metrics/ModuleLength
6 changes: 2 additions & 4 deletions lib/rbnacl/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ def check_hmac_key(string, _description)
#
# @param string [#to_str] The input string
def check_string_validation(string)
unless string.respond_to? :to_str
raise TypeError, "can't convert #{string.class} into String with #to_str"
end
raise TypeError, "can't convert #{string.class} into String with #to_str" unless string.respond_to? :to_str

string = string.to_str

Expand Down Expand Up @@ -274,7 +272,7 @@ def verify16!(one, two)
#
# @return [String] Tasty, tasty hexadecimal
def bin2hex(bytes)
bytes.to_s.unpack("H*").first
bytes.to_s.unpack1("H*")
end

# Hex decodes a message
Expand Down
2 changes: 1 addition & 1 deletion lib/rbnacl/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
# NaCl/libsodium for Ruby
module RbNaCl
# The library's version
VERSION = "5.0.0"
VERSION = "6.0.0.pre".freeze
end
4 changes: 1 addition & 3 deletions rbnacl.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

# frozen_string_literal: true

lib = File.expand_path("../lib", __FILE__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "rbnacl/version"

Expand All @@ -23,7 +22,6 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.2.6"
spec.platform = "jruby" if defined? JRUBY_VERSION

spec.add_runtime_dependency "ffi"

Expand Down
4 changes: 2 additions & 2 deletions spec/shared/hmac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

context "#update" do
it "returns hexdigest when produces an authenticator" do
expect(authenticator.update(message)).to eq mult_tag.unpack("H*").first
expect(authenticator.update(message)).to eq mult_tag.unpack1("H*")
end
end

Expand All @@ -39,7 +39,7 @@

context "#hexdigest" do
it "returns hex authenticator" do
expect(authenticator.hexdigest).to eq tag.unpack("H*").first
expect(authenticator.hexdigest).to eq tag.unpack1("H*")
end
end
end
Expand Down

0 comments on commit 9a70273

Please sign in to comment.