Sha256: edb121971cdbbfc18542d120b92565010c21a0d3bfe95211750c1a3dd28f03f8

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

# encoding: binary
# frozen_string_literal: true

require "rbnacl/sodium"

module RbNaCl
  module Sodium
    # libsodium version API
    module Version
      MINIMUM_LIBSODIUM_VERSION = [0, 4, 3].freeze
      MINIMUM_LIBSODIUM_VERSION_FOR_ARGON2 = [1, 0, 9].freeze
      MINIMUM_LIBSODIUM_VERSION_FOR_ARGON2ID = [1, 0, 13].freeze

      extend Sodium
      attach_function :sodium_version_string, [], :string

      STRING = sodium_version_string
      MAJOR, MINOR, PATCH = STRING.split(".").map(&:to_i)

      INSTALLED_VERSION = [MAJOR, MINOR, PATCH].freeze

      case INSTALLED_VERSION <=> MINIMUM_LIBSODIUM_VERSION
      when -1
        raise "Sorry, you need to install libsodium #{MINIMUM_LIBSODIUM_VERSION}+. You have #{Version::STRING} installed"
      end

      ARGON2_SUPPORTED = (INSTALLED_VERSION <=> MINIMUM_LIBSODIUM_VERSION_FOR_ARGON2) != -1
      ARGON2ID_SUPPORTED = (INSTALLED_VERSION <=> MINIMUM_LIBSODIUM_VERSION_FOR_ARGON2ID) != -1

      # Determine if a given feature is supported based on Sodium version
      def self.supported_version?(version)
        Gem::Version.new(sodium_version_string) >= Gem::Version.new(version)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rbnacl-7.1.2 lib/rbnacl/sodium/version.rb
rbnacl-7.1.1 lib/rbnacl/sodium/version.rb
rbnacl-7.1.0 lib/rbnacl/sodium/version.rb
rbnacl-7.0.0 lib/rbnacl/sodium/version.rb
rbnacl-6.0.1 lib/rbnacl/sodium/version.rb
rbnacl-6.0.0 lib/rbnacl/sodium/version.rb