Sha256: 19df8fe460923f216044b2311bd6ab670d5c1cf8f8c1a4aa2cb98d0a73612bf3

Contents?: true

Size: 1.48 KB

Versions: 5

Compression:

Stored size: 1.48 KB

Contents

# encoding: binary
# frozen_string_literal: true

if RbNaCl::Sodium::Version::ARGON2_SUPPORTED
  RSpec.describe RbNaCl::PasswordHash::Argon2 do
    let(:reference_password) { vector :argon2_password }
    let(:reference_salt)     { vector :argon2_salt }
    let(:reference_opslimit) { RbNaCl::TEST_VECTORS[:argon2_opslimit] }
    let(:reference_memlimit) { RbNaCl::TEST_VECTORS[:argon2_memlimit] }
    let(:reference_digest)   { vector :argon2_digest }
    let(:reference_outlen)   { RbNaCl::TEST_VECTORS[:argon2_outlen] }

    let(:str_ref_password) { RbNaCl::TEST_VECTORS[:argon2_str_passwd] }
    let(:str_ref_digest)   { RbNaCl::TEST_VECTORS[:argon2_str_digest] }

    it "calculates the correct digest for a reference password/salt" do
      digest = RbNaCl::PasswordHash.argon2(
        reference_password,
        reference_salt,
        reference_opslimit,
        reference_memlimit,
        reference_outlen
      )

      expect(digest).to eq reference_digest
    end

    it "verifies password" do
      valid = RbNaCl::PasswordHash.argon2_valid?(str_ref_password, str_ref_digest)
      expect(valid).to eq true
    end

    it "creates digest string" do
      digest = RbNaCl::PasswordHash.argon2_str(str_ref_password)
      valid = RbNaCl::PasswordHash.argon2_valid?(str_ref_password, digest)
      expect(valid).to eq true
    end

    it "fails on invalid passwords" do
      valid = RbNaCl::PasswordHash.argon2_valid?("wrongpassword", str_ref_digest)
      expect(valid).to eq false
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rbnacl-5.0.0 spec/rbnacl/password_hash/argon2_spec.rb
rbnacl-4.0.2 spec/rbnacl/password_hash/argon2_spec.rb
rbnacl-4.0.1 spec/rbnacl/password_hash/argon2_spec.rb
rbnacl-4.0.0 spec/rbnacl/password_hash/argon2_spec.rb
rbnacl-4.0.0.pre spec/rbnacl/password_hash/argon2_spec.rb