Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross hash for JS and Native #3070

Merged
merged 3 commits into from
Nov 30, 2022

Conversation

armanbilge
Copy link
Member

test("sha256")(forAll((s: String) => checkDigest(sha256, "SHA-256", s)))
test("sha384")(forAll((s: String) => checkDigest(sha384, "SHA-384", s)))
test("sha512")(forAll((s: String) => checkDigest(sha512, "SHA-512", s)))
if (isJVM) test("md2")(forAllF((s: String) => checkDigest(md2, "MD2", s)))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, crypto is weird, since ultimately it depends on availability of algorithms at runtime. Seems that default OpenSSL builds (also used by Node.js) don't include MD2. But an alternative build could.

/** Computes the digest of the source stream, emitting the digest as a chunk
* after completion of the source stream.
*/
private[this] def digest[F[_]](digest: => Ptr[EVP_MD])(implicit F: Sync[F]): Pipe[F, Byte, Byte] =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I caved and added a Sync constraint here, unlike the JVM/JS implementations. Since we are allocating and freeing native memory I didn't see a way around it.

This might end up being annoying in practice, especially for cross-builds. Maybe a capability typeclass Hash[F] would be a better design.

@mpilquist mpilquist merged commit 4156717 into typelevel:main Nov 30, 2022
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.

None yet

2 participants