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 4e4745d
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 40 deletions.
16 changes: 13 additions & 3 deletions .rubocop.yml
@@ -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 All @@ -42,11 +49,14 @@ Performance/UnfreezeString:
# Style
#

Style/StringLiterals:
EnforcedStyle: double_quotes
Style/AccessModifierDeclarations:
Enabled: false

Style/GlobalVars:
Enabled: false

Style/SafeNavigation:
Enabled: false

Style/StringLiterals:
EnforcedStyle: double_quotes
13 changes: 6 additions & 7 deletions .travis.yml
Expand Up @@ -2,21 +2,20 @@ language: ruby
cache: bundler

before_install:
- sudo add-apt-repository -y ppa:chris-lea/libsodium
- sudo apt-get update -q
- sudo apt-get install libsodium-dev
- gem update --system
- gem --version
- gem install bundler -v 1.16.1
- gem install bundler -v 1.17.1
- bundle --version

rvm:
- jruby-9.1.15.0
- 2.2
- 2.3
- 2.4.3
- 2.5.0

env:
- LIBSODIUM_VERSION=1.0.0 # Minimum supported
- LIBSODIUM_VERSION=1.0.16 # Latest released
- 2.4
- 2.5

matrix:
fast_finish: true
Expand Down
3 changes: 1 addition & 2 deletions Gemfile
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
3 changes: 0 additions & 3 deletions README.md
Expand Up @@ -101,9 +101,6 @@ Note: [Windows installation instructions are available](https://github.com/crypt

### libsodium

**NOTE: Want to avoid the hassle of installing libsodium? Use the
[rbnacl-libsodium](https://github.com/crypto-rb/rbnacl-libsodium) gem**

To use RbNaCl, you will need to install libsodium:

https://github.com/jedisct1/libsodium
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
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]
10 changes: 7 additions & 3 deletions lib/rbnacl.rb
@@ -1,6 +1,12 @@
# 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. "\
"See https://github.com/crypto-rb/rbnacl#installation"
end

require "rbnacl/version"
require "rbnacl/sodium"
require "rbnacl/sodium/version"
Expand Down Expand Up @@ -69,9 +75,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
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
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
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
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
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
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
@@ -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
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 4e4745d

Please sign in to comment.