argon2id 0.1.0-x64-mingw-ucrt → 0.1.2-x64-mingw-ucrt

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d820a1d1c0ea2ed9c0a495e4ca4b185ca7810d7de6f5d6af2c79c2b937c1cdcd
4
- data.tar.gz: 86686f7891867e90343e912e1bf01681a596c572eef224195785042f029a1c86
3
+ metadata.gz: b20ba7560ad0d4466c3b79ef5124b4ba499875906e0371f226e4ab0b19e1b18d
4
+ data.tar.gz: 0e7c00a7b12524c7052a5a181250b88053e5e4db7465e4487a00528c13677924
5
5
  SHA512:
6
- metadata.gz: e6a9ed3142acfdbd23906e8cbda550ff4c3c276decbc784a28fb756c5df481d61eda41a94bcaa41bb6527d5ca8329b3baf8f756c138a9cac9a489a076f557488
7
- data.tar.gz: d0fe395957a35dcb685e7a18b2d06e6e3065bab4e112a16d957106404b7e8919c27f6c773dec022396ab41d037884b756635e90661f0a91a6f1417f1b9d851db
6
+ metadata.gz: 9760bfb485ef65c92067de09874c2b98c94db5ea4cc404681f9c34fe1ced9841bea823ab1163e3235dc7c64520f9adb5a8c644f758c90994467ab17a9c384587
7
+ data.tar.gz: 4f7c6115e96ace87a740a5200e2cff9c63be6079b015dd45b5f9541d9d76a56256e598e7dc4a3be5e45e8bc18e83f36911c75d5f70f15cb81443011cf10a4522
data/CHANGELOG.md CHANGED
@@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.2] - 2024-11-01
9
+
10
+ ### Fixed
11
+
12
+ - Validate that the encoded hash passed to Argon2id::Password.new is a
13
+ null-terminated C string, raising an ArgumentError if it contains extra null
14
+ bytes
15
+
16
+ ## [0.1.1] - 2024-11-01
17
+
18
+ ### Added
19
+
20
+ - RDoc documentation for the API
21
+
22
+ ### Fixed
23
+
24
+ - Saved a superfluous extra byte when allocating the buffer for the encoded
25
+ hash
26
+
8
27
  ## [0.1.0] - 2024-10-31
9
28
 
10
29
  ### Added
@@ -13,4 +32,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
32
  reference C implementation of Argon2, the password-hashing function that won
14
33
  the Password Hashing Competition.
15
34
 
35
+ [0.1.2]: https://github.com/mudge/argon2id/releases/tag/v0.1.2
36
+ [0.1.1]: https://github.com/mudge/argon2id/releases/tag/v0.1.1
16
37
  [0.1.0]: https://github.com/mudge/argon2id/releases/tag/v0.1.0
data/README.md CHANGED
@@ -1,18 +1,22 @@
1
- # Argon2id - Ruby bindings to the award-winning password-hashing function
1
+ # Argon2id - Ruby bindings to the OWASP recommended password-hashing function
2
2
 
3
3
  Ruby bindings to the reference C implementation of [Argon2][], the password-hashing
4
4
  function that won the 2015 [Password Hashing Competition][].
5
5
 
6
6
  [![Build Status](https://github.com/mudge/argon2id/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/mudge/argon2id/actions)
7
7
 
8
- **Current version:** 0.1.0
8
+ **Current version:** 0.1.2
9
9
  **Bundled Argon2 version:** libargon2.1 (20190702)
10
10
 
11
11
  ```ruby
12
12
  Argon2::Password.create("opensesame").to_s
13
13
  #=> "$argon2id$v=19$m=19456,t=2,p=1$ZS2nBFWBpnt28HjtzNOW4w$SQ+p+dIcWbpzWpZQ/ZZFj8IQkyhYZf127U4QdkRmKFU"
14
- Argon2::Password.create("opensesame") == "opensesame" #=> true
15
- Argon2::Password.create("opensesame") == "notopensesame" #=> false
14
+
15
+ Argon2::Password.create("opensesame") == "opensesame"
16
+ #=> true
17
+
18
+ Argon2::Password.new("$argon2id$v=19$m=19456,t=2,p=1$ZS2nBFWBpnt28HjtzNOW4w$SQ+p+dIcWbpzWpZQ/ZZFj8IQkyhYZf127U4QdkRmKFU") == "opensesame"
19
+ #=> true
16
20
  ```
17
21
 
18
22
  ## Table of contents
@@ -156,16 +160,27 @@ This gem requires the following to run:
156
160
 
157
161
  ### Native gems
158
162
 
163
+ Where possible, a pre-compiled native gem will be provided for the following platforms:
164
+
165
+ * Linux
166
+ * `aarch64-linux` and `arm-linux` (requires [glibc](https://www.gnu.org/software/libc/) 2.29+)
167
+ * `x86-linux` and `x86_64-linux` (requires [glibc](https://www.gnu.org/software/libc/) 2.17+)
168
+ * [musl](https://musl.libc.org/)-based systems such as [Alpine](https://alpinelinux.org) are supported as long as a [glibc-compatible library is installed](https://wiki.alpinelinux.org/wiki/Running_glibc_programs)
169
+ * macOS `x86_64-darwin` and `arm64-darwin`
170
+ * Windows `x64-mingw32` and `x64-mingw-ucrt`
171
+
172
+ ### Verifying the gems
173
+
159
174
  SHA256 checksums are included in the [release
160
175
  notes](https://github.com/mudge/argon2id/releases) for each version and can be
161
176
  checked with `sha256sum`, e.g.
162
177
 
163
178
  ```console
164
- $ gem fetch argon2id -v 0.1.0
165
- Fetching argon2id-0.1.0-arm64-darwin.gem
166
- Downloaded argon2id-0.1.0-arm64-darwin
167
- $ sha256sum argon2id-0.1.0-arm64-darwin.gem
168
- e71e4acaa5cae6ca763bc078bde121fb76ea07bad72bc471c9efd2ba444be604 argon2id-0.1.0-arm64-darwin.gem
179
+ $ gem fetch argon2id -v 0.1.1
180
+ Fetching argon2id-0.1.1-arm64-darwin.gem
181
+ Downloaded argon2id-0.1.1-arm64-darwin
182
+ $ sha256sum argon2id-0.1.1-arm64-darwin.gem
183
+ 8d47464edf847ca52c1d41cac1a9feff376e9a1e7c0a98ab58df846990caa1bb argon2id-0.1.1-arm64-darwin.gem
169
184
  ```
170
185
 
171
186
  [GPG](https://www.gnupg.org/) signatures are attached to each release (the
@@ -175,8 +190,8 @@ from a public keyserver, e.g. `gpg --keyserver keyserver.ubuntu.com --recv-key
175
190
  0x39AC3530070E0F75`):
176
191
 
177
192
  ```console
178
- $ gpg --verify argon2id-0.1.0-arm64-darwin.gem.sig argon2id-0.1.0-arm64-darwin.gem
179
- gpg: Signature made Thu 31 Oct 11:16:18 2024 BST
193
+ $ gpg --verify argon2id-0.1.1-arm64-darwin.gem.sig argon2id-0.1.1-arm64-darwin.gem
194
+ gpg: Signature made Fri 1 Nov 07:24:16 2024 GMT
180
195
  gpg: using RSA key 702609D9C790F45B577D7BEC39AC3530070E0F75
181
196
  gpg: Good signature from "Paul Mucur <mudge@mudge.name>" [unknown]
182
197
  gpg: aka "Paul Mucur <paul@ghostcassette.com>" [unknown]
@@ -229,7 +244,7 @@ Issues](https://github.com/mudge/argon2id/issues).
229
244
 
230
245
  ## License
231
246
 
232
- This library is licensed under the BSD 3-Clause License, see `LICENSE.txt`.
247
+ This library is licensed under the BSD 3-Clause License, see `LICENSE`.
233
248
 
234
249
  Copyright © 2024, Paul Mucur.
235
250
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require "rake/extensiontask"
2
2
  require "rake_compiler_dock"
3
- require "rake/testtask"
3
+ require "minitest/test_task"
4
4
 
5
5
  CLEAN.add("lib/**/*.{o,so,bundle}", "pkg")
6
6
 
@@ -27,9 +27,7 @@ Rake::ExtensionTask.new("argon2id", gemspec) do |e|
27
27
  e.cross_platform = cross_platforms
28
28
  end
29
29
 
30
- Rake::TestTask.new do |t|
31
- t.warning = true
32
- end
30
+ Minitest::TestTask.create
33
31
 
34
32
  begin
35
33
  require "ruby_memcheck"
data/argon2id.gemspec CHANGED
@@ -51,6 +51,7 @@ Gem::Specification.new do |s|
51
51
  "test/test_password.rb",
52
52
  "test/test_verify.rb"
53
53
  ]
54
+ s.rdoc_options = ["--main", "README.md"]
54
55
 
55
56
  s.add_development_dependency("rake-compiler", "~> 1.2")
56
57
  s.add_development_dependency("rake-compiler-dock", "~> 1.5")
@@ -7,6 +7,17 @@
7
7
 
8
8
  VALUE mArgon2id, cArgon2idError;
9
9
 
10
+ /* call-seq: hash_encoded(t_cost, m_cost, parallelism, pwd, salt, output_len)
11
+ *
12
+ * Hashes a password with Argon2id, producing an encoded hash.
13
+ *
14
+ * - +t_cost+: number of iterations
15
+ * - +m_cost+: sets memory usage to +m_cost+ kibibytes
16
+ * - +parallelism+: number of threads and compute lanes
17
+ * - +pwd+: the password
18
+ * - +salt+: the salt
19
+ * - +output_len+: desired length of the hash in bytes
20
+ */
10
21
  static VALUE
11
22
  rb_argon2id_hash_encoded(VALUE module, VALUE iterations, VALUE memory, VALUE threads, VALUE pwd, VALUE salt, VALUE hashlen)
12
23
  {
@@ -24,7 +35,7 @@ rb_argon2id_hash_encoded(VALUE module, VALUE iterations, VALUE memory, VALUE thr
24
35
  outlen = FIX2INT(hashlen);
25
36
 
26
37
  encodedlen = argon2_encodedlen(t_cost, m_cost, parallelism, (uint32_t)RSTRING_LEN(salt), (uint32_t)outlen, Argon2_id);
27
- encoded = malloc(encodedlen + 1);
38
+ encoded = malloc(encodedlen);
28
39
  if (!encoded) {
29
40
  rb_raise(rb_eNoMemError, "not enough memory to allocate for encoded password");
30
41
  }
@@ -36,19 +47,23 @@ rb_argon2id_hash_encoded(VALUE module, VALUE iterations, VALUE memory, VALUE thr
36
47
  rb_raise(cArgon2idError, "%s", argon2_error_message(result));
37
48
  }
38
49
 
39
- hash = rb_str_new(encoded, strlen(encoded));
50
+ hash = rb_str_new_cstr(encoded);
40
51
  free(encoded);
41
52
 
42
53
  return hash;
43
54
  }
44
55
 
56
+ /* call-seq: verify(encoded, pwd)
57
+ *
58
+ * Verifies a password against an encoded string.
59
+ */
45
60
  static VALUE
46
61
  rb_argon2id_verify(VALUE module, VALUE encoded, VALUE pwd) {
47
62
  int result;
48
63
 
49
64
  UNUSED(module);
50
65
 
51
- result = argon2id_verify(StringValuePtr(encoded), StringValuePtr(pwd), RSTRING_LEN(pwd));
66
+ result = argon2id_verify(StringValueCStr(encoded), StringValuePtr(pwd), RSTRING_LEN(pwd));
52
67
  if (result == ARGON2_OK) {
53
68
  return Qtrue;
54
69
  }
data/lib/3.1/argon2id.so CHANGED
Binary file
data/lib/3.2/argon2id.so CHANGED
Binary file
data/lib/3.3/argon2id.so CHANGED
Binary file
@@ -3,9 +3,42 @@
3
3
  require "openssl"
4
4
 
5
5
  module Argon2id
6
+ # The Password class encapsulates an encoded Argon2id password hash.
7
+ #
8
+ # To hash a plain text password, use Argon2id::Password.create:
9
+ #
10
+ # password = Argon2id::Password.create("password")
11
+ # password.to_s
12
+ # #=> "$argon2id$v=19$m=19456,t=2,p=1$+Lrjry9Ifq0poLr15OGU1Q$utkDvejJB0ugwm4s9+a+vF6+1a/W+Y3CYa5Wte/85ig"
13
+ #
14
+ # To verify an encoded Argon2id password hash, use Argon2id::Password.new:
15
+ #
16
+ # password = Argon2id::Password.new("$argon2id$v=19$m=19456,t=2,p=1$+Lrjry9Ifq0poLr15OGU1Q$utkDvejJB0ugwm4s9+a+vF6+1a/W+Y3CYa5Wte/85ig")
17
+ # password == "password"
18
+ # #=> true
6
19
  class Password
20
+ # The encoded password hash.
7
21
  attr_reader :encoded
8
22
 
23
+ # Create a new Password object that hashes a given plain text password +pwd+.
24
+ #
25
+ # - +:t_cost+: integer (default 2) the "time cost" given as a number of iterations
26
+ # - +:m_cost+: integer (default 19456) the "memory cost" given in kibibytes
27
+ # - +:parallelism+: integer (default 1) the number of threads and compute lanes to use
28
+ # - +:salt_len+: integer (default 16) the salt size in bytes
29
+ # - +:output_len+: integer (default 32) the desired length of the hash in bytes
30
+ #
31
+ # For example, with the default configuration:
32
+ #
33
+ # password = Argon2id::Password.create("password")
34
+ # password.to_s
35
+ # #=> "$argon2id$v=19$m=19456,t=2,p=1$FI8yp1gXbthJCskBlpKPoQ$nOfCCpS2r+I8GRN71cZND4cskn7YKBNzuHUEO3YpY2s"
36
+ #
37
+ # When overriding the configuration:
38
+ #
39
+ # password = Argon2id::Password.create("password", t_cost: 3, m_cost: 12288)
40
+ # password.to_s
41
+ # #=> "$argon2id$v=19$m=12288,t=3,p=1$JigW7fFn+N3NImt+aWpuzw$eM5F1cKeIBALNTU6LuWra75Zi2nymGvQLWzJzVFv0Nc"
9
42
  def self.create(pwd, t_cost: Argon2id.t_cost, m_cost: Argon2id.m_cost, parallelism: Argon2id.parallelism, salt_len: Argon2id.salt_len, output_len: Argon2id.output_len)
10
43
  new(
11
44
  Argon2id.hash_encoded(
@@ -19,14 +52,26 @@ module Argon2id
19
52
  )
20
53
  end
21
54
 
55
+ # call-seq: Argon2id::Password.new(encoded)
56
+ #
57
+ # Create a new Password with the given encoded password hash.
58
+ #
59
+ # password = Argon2id::Password.new("$argon2id$v=19$m=19456,t=2,p=1$FI8yp1gXbthJCskBlpKPoQ$nOfCCpS2r+I8GRN71cZND4cskn7YKBNzuHUEO3YpY2s")
22
60
  def initialize(encoded)
23
61
  @encoded = encoded
24
62
  end
25
63
 
64
+ # Return the encoded password hash.
26
65
  def to_s
27
66
  encoded
28
67
  end
29
68
 
69
+ # Compare the password with given plain text, returning true if it verifies
70
+ # successfully.
71
+ #
72
+ # password = Argon2id::Password.new("$argon2id$v=19$m=19456,t=2,p=1$FI8yp1gXbthJCskBlpKPoQ$nOfCCpS2r+I8GRN71cZND4cskn7YKBNzuHUEO3YpY2s")
73
+ # password == "password" #=> true
74
+ # password == "notpassword" #=> false
30
75
  def ==(other)
31
76
  Argon2id.verify(encoded, String(other))
32
77
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Argon2id
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/argon2id.rb CHANGED
@@ -11,10 +11,19 @@ require "argon2id/version"
11
11
  require "argon2id/password"
12
12
 
13
13
  module Argon2id
14
+ # The default "time cost" of 2 iterations recommended by OWASP.
14
15
  DEFAULT_T_COST = 2
16
+
17
+ # The default "memory cost" of 19 mebibytes recommended by OWASP.
15
18
  DEFAULT_M_COST = 19456
19
+
20
+ # The default 1 thread and compute lane recommended by OWASP.
16
21
  DEFAULT_PARALLELISM = 1
22
+
23
+ # The default salt length of 16 bytes.
17
24
  DEFAULT_SALT_LEN = 16
25
+
26
+ # The default desired hash length of 32 bytes.
18
27
  DEFAULT_OUTPUT_LEN = 32
19
28
 
20
29
  @t_cost = DEFAULT_T_COST
@@ -24,6 +33,19 @@ module Argon2id
24
33
  @output_len = DEFAULT_OUTPUT_LEN
25
34
 
26
35
  class << self
27
- attr_accessor :t_cost, :m_cost, :parallelism, :salt_len, :output_len
36
+ # The default number of iterations used by Argon2id::Password.create
37
+ attr_accessor :t_cost
38
+
39
+ # The default memory cost in kibibytes used by Argon2id::Password.create
40
+ attr_accessor :m_cost
41
+
42
+ # The default number of threads and compute lanes used by Argon2id::Password.create
43
+ attr_accessor :parallelism
44
+
45
+ # The default salt size in bytes used by Argon2id::Password.create
46
+ attr_accessor :salt_len
47
+
48
+ # The default desired length of the hash in bytes used by Argon2id::Password.create
49
+ attr_accessor :output_len
28
50
  end
29
51
  end
@@ -5,34 +5,28 @@ require "argon2id"
5
5
 
6
6
  class TestHashEncoded < Minitest::Test
7
7
  def test_valid_password_and_salt_encodes_successfully
8
- encoded = Argon2id.hash_encoded(2, 19456, 1, "opensesame", OpenSSL::Random.random_bytes(16), 32)
8
+ encoded = Argon2id.hash_encoded(2, 256, 1, "password", "somesalt", 32)
9
9
 
10
- assert encoded.start_with?("$argon2id$")
10
+ assert_equal "$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4", encoded
11
11
  end
12
12
 
13
13
  def test_valid_password_does_not_include_trailing_null_byte
14
- encoded = Argon2id.hash_encoded(2, 19456, 1, "opensesame", OpenSSL::Random.random_bytes(16), 32)
14
+ encoded = Argon2id.hash_encoded(2, 256, 1, "password", "somesalt", 32)
15
15
 
16
16
  refute encoded.end_with?("\x00")
17
17
  end
18
18
 
19
19
  def test_raises_with_too_short_output
20
20
  error = assert_raises(Argon2id::Error) do
21
- Argon2id.hash_encoded(2, 19456, 1, "opensesame", OpenSSL::Random.random_bytes(16), 1)
21
+ Argon2id.hash_encoded(2, 256, 1, "password", "somesalt", 1)
22
22
  end
23
23
 
24
24
  assert_equal "Output is too short", error.message
25
25
  end
26
26
 
27
- def test_raises_with_too_large_output
28
- assert_raises(RangeError) do
29
- Argon2id.hash_encoded(2, 19456, 1, "opensesame", OpenSSL::Random.random_bytes(16), 4294967296)
30
- end
31
- end
32
-
33
27
  def test_raises_with_too_few_lanes
34
28
  error = assert_raises(Argon2id::Error) do
35
- Argon2id.hash_encoded(2, 19456, 0, "opensesame", OpenSSL::Random.random_bytes(16), 32)
29
+ Argon2id.hash_encoded(2, 256, 0, "password", "somesalt", 32)
36
30
  end
37
31
 
38
32
  assert_equal "Too few lanes", error.message
@@ -40,51 +34,25 @@ class TestHashEncoded < Minitest::Test
40
34
 
41
35
  def test_raises_with_too_small_memory_cost
42
36
  error = assert_raises(Argon2id::Error) do
43
- Argon2id.hash_encoded(2, 0, 1, "opensesame", OpenSSL::Random.random_bytes(16), 32)
37
+ Argon2id.hash_encoded(2, 0, 1, "password", "somesalt", 32)
44
38
  end
45
39
 
46
40
  assert_equal "Memory cost is too small", error.message
47
41
  end
48
42
 
49
- def test_raises_with_too_large_memory_cost
50
- assert_raises(RangeError) do
51
- Argon2id.hash_encoded(2, 4294967296, 1, "opensesame", OpenSSL::Random.random_bytes(16), 32)
52
- end
53
- end
54
-
55
43
  def test_raises_with_too_small_time_cost
56
44
  error = assert_raises(Argon2id::Error) do
57
- Argon2id.hash_encoded(0, 19456, 1, "opensesame", OpenSSL::Random.random_bytes(16), 32)
45
+ Argon2id.hash_encoded(0, 256, 1, "password", "somesalt", 32)
58
46
  end
59
47
 
60
48
  assert_equal "Time cost is too small", error.message
61
49
  end
62
50
 
63
- def test_raises_with_too_large_time_cost
64
- assert_raises(RangeError) do
65
- Argon2id.hash_encoded(4294967296, 19456, 1, "opensesame", OpenSSL::Random.random_bytes(16), 32)
66
- end
67
- end
68
-
69
- def test_raises_with_too_long_password
70
- error = assert_raises(Argon2id::Error) do
71
- Argon2id.hash_encoded(2, 19456, 1, "a" * 4294967296, OpenSSL::Random.random_bytes(16), 32)
72
- end
73
-
74
- assert_equal "Password is too long", error.message
75
- end
76
-
77
51
  def test_raises_with_too_short_salt
78
52
  error = assert_raises(Argon2id::Error) do
79
- Argon2id.hash_encoded(2, 19456, 1, "opensesame", OpenSSL::Random.random_bytes(1), 32)
53
+ Argon2id.hash_encoded(0, 256, 1, "password", "", 32)
80
54
  end
81
55
 
82
56
  assert_equal "Salt is too short", error.message
83
57
  end
84
-
85
- def test_raises_with_too_long_salt
86
- assert_raises(RangeError) do
87
- Argon2id.hash_encoded(2, 19456, 1, "opensesame", OpenSSL::Random.random_bytes(4294967296), 32)
88
- end
89
- end
90
58
  end
@@ -13,33 +13,33 @@ class TestPassword < Minitest::Test
13
13
  end
14
14
 
15
15
  def test_create_options_can_override_parameters
16
- password = Argon2id::Password.create("opensesame", t_cost: 3, m_cost: 12288)
16
+ password = Argon2id::Password.create("opensesame", t_cost: 2, m_cost: 256)
17
17
 
18
- assert password.to_s.include?("t=3")
19
- assert password.to_s.include?("m=12288")
18
+ assert password.to_s.include?("t=2")
19
+ assert password.to_s.include?("m=256")
20
20
  end
21
21
 
22
22
  def test_create_uses_argon2id_configuration
23
- Argon2id.parallelism = 4
24
- Argon2id.m_cost = 9216
23
+ Argon2id.t_cost = 2
24
+ Argon2id.m_cost = 256
25
25
 
26
26
  password = Argon2id::Password.create("opensesame")
27
27
 
28
- assert password.to_s.include?("p=4")
29
- assert password.to_s.include?("m=9216")
28
+ assert password.to_s.include?("t=2")
29
+ assert password.to_s.include?("m=256")
30
30
  ensure
31
- Argon2id.parallelism = Argon2id::DEFAULT_PARALLELISM
31
+ Argon2id.t_cost = Argon2id::DEFAULT_T_COST
32
32
  Argon2id.m_cost = Argon2id::DEFAULT_M_COST
33
33
  end
34
34
 
35
35
  def test_create_coerces_pwd_to_string
36
- password = Argon2id::Password.create(123)
36
+ password = Argon2id::Password.create(123, t_cost: 2, m_cost: 256)
37
37
 
38
38
  assert password.to_s.start_with?("$argon2id$")
39
39
  end
40
40
 
41
41
  def test_create_coerces_costs_to_integer
42
- password = Argon2id::Password.create("opensesame", t_cost: "5", m_cost: "7168", parallelism: "1", salt_len: "16", output_len: "32")
42
+ password = Argon2id::Password.create("opensesame", t_cost: "2", m_cost: "256", parallelism: "1", salt_len: "8", output_len: "32")
43
43
 
44
44
  assert password.to_s.start_with?("$argon2id$")
45
45
  end
@@ -51,25 +51,25 @@ class TestPassword < Minitest::Test
51
51
  end
52
52
 
53
53
  def test_equals_correct_password
54
- password = Argon2id::Password.create("opensesame")
54
+ password = Argon2id::Password.create("opensesame", t_cost: 2, m_cost: 256)
55
55
 
56
56
  assert password == "opensesame"
57
57
  end
58
58
 
59
59
  def test_does_not_equal_invalid_password
60
- password = Argon2id::Password.create("opensesame")
60
+ password = Argon2id::Password.create("opensesame", t_cost: 2, m_cost: 256)
61
61
 
62
62
  refute password == "notopensesame"
63
63
  end
64
64
 
65
65
  def test_is_password_returns_true_with_correct_password
66
- password = Argon2id::Password.create("opensesame")
66
+ password = Argon2id::Password.create("opensesame", t_cost: 2, m_cost: 256)
67
67
 
68
68
  assert password.is_password?("opensesame")
69
69
  end
70
70
 
71
71
  def test_is_password_returns_false_with_incorrect_password
72
- password = Argon2id::Password.create("opensesame")
72
+ password = Argon2id::Password.create("opensesame", t_cost: 2, m_cost: 256)
73
73
 
74
74
  refute password.is_password?("notopensesame")
75
75
  end
data/test/test_verify.rb CHANGED
@@ -5,15 +5,17 @@ require "argon2id"
5
5
 
6
6
  class TestVerify < Minitest::Test
7
7
  def test_returns_true_with_correct_password
8
- encoded = Argon2id.hash_encoded(2, 19456, 1, "opensesame", OpenSSL::Random.random_bytes(16), 32)
9
-
10
- assert Argon2id.verify(encoded, "opensesame")
8
+ assert Argon2id.verify(
9
+ "$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4",
10
+ "password"
11
+ )
11
12
  end
12
13
 
13
14
  def test_returns_false_with_incorrect_password
14
- encoded = Argon2id.hash_encoded(2, 19456, 1, "opensesame", OpenSSL::Random.random_bytes(16), 32)
15
-
16
- refute Argon2id.verify(encoded, "notopensesame")
15
+ refute Argon2id.verify(
16
+ "$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4",
17
+ "not password"
18
+ )
17
19
  end
18
20
 
19
21
  def test_raises_if_given_invalid_encoded
@@ -21,4 +23,13 @@ class TestVerify < Minitest::Test
21
23
  Argon2id.verify("", "opensesame")
22
24
  end
23
25
  end
26
+
27
+ def test_raises_if_given_encoded_with_null_byte
28
+ assert_raises(ArgumentError) do
29
+ Argon2id.verify(
30
+ "$argon2id$v=19$m=256,t=2,p=1$c29tZXNhbHQ$nf65EOgLrQMR/uIPnA4rEsF5h7TKyQwu9U1bMCHGi/4\x00foo",
31
+ "password"
32
+ )
33
+ end
34
+ end
24
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: argon2id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: x64-mingw-ucrt
6
6
  authors:
7
7
  - Paul Mucur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-31 00:00:00.000000000 Z
11
+ date: 2024-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -102,7 +102,9 @@ metadata:
102
102
  source_code_uri: https://github.com/mudge/argon2id
103
103
  rubygems_mfa_required: 'true'
104
104
  post_install_message:
105
- rdoc_options: []
105
+ rdoc_options:
106
+ - "--main"
107
+ - README.md
106
108
  require_paths:
107
109
  - lib
108
110
  required_ruby_version: !ruby/object:Gem::Requirement