Skip to content

Test Crypt3 - #345

Merged
trans merged 1 commit into
mainfrom
test/crypt3
Nov 17, 2026
Merged

trans merged 1 commit into
mainfrom
test/crypt3

Conversation

@trans

@trans trans commented Nov 17, 2026

Copy link
Copy Markdown
Member

Crypt3 came into Facets from the crypt3 gem in 3.2.0, and nothing tested it: lib/standard/facets/crypt3.rb was the only file that mentioned it. The crypt3 repository is now retired in favour of this module, so Facets holds the only maintained copy.

test/standard/test_crypt3.rb adds 13 tests:

  • crypt gives the same md5 hashes as crypt(3) for six known password and salt pairs, and the same hash as Apache for the $apr1$ magic. The vectors are the crypt3 gem's own.
  • crypt is deterministic for a given salt across md5, sha1, sha256, sha384 and sha512, differs by algorithm, keeps the magic and salt at the front, makes a random 8 character salt when given none, and raises ArgumentError for an unknown algorithm.
  • check accepts the right password, rejects a wrong one, reads the magic from the hash, and depends on the algorithm.
  • generate_salt gives the size asked for, from the crypt(3) base 64 characters.

rmd160 is left out: digest/rmd160 isn't available on every Ruby in the CI matrix.

No change to the library.

Testing

  • rubytest -Ilib/core -Ilib/standard test/standard/test_crypt3.rb: 13 tests, all passing on Ruby 3.4.9.
  • rake test:standard passes.
  • Separately, the crypt3 gem 1.1.6 and this module gave identical hashes for 24 password and algorithm pairs, rmd160 included, and the md5 result matched openssl passwd -1.

🤖 Generated with Claude Code

Crypt3 came in from the crypt3 gem in 3.2.0 without tests. Check it
against that gem's known crypt(3) and Apache hashes, and cover check,
generate_salt, the random salt and the other algorithms.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@trans
trans merged commit 6b26c71 into main Nov 17, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant