korlibs / korlibs/korlibs-crypto

Krypto buffered stream hashing extension functions

Open
#18 4 comments 0 reactions 0 assignees View on GitHub
good first issue help wanted
Dominant language
Kotlin
Stars
12
Forks
3
PR merge metrics
No merged PRs in 30d

Description

I noticed that currently, krypto only has extension functions to compute the hash of a `ByteArray`.
However, it is not too difficult to implement said hashing extension functions, and would be a good quality of life inclusion.

Using the JVM-only `InputStream`:
```kt
fun InputStream.hash(algo: HasherFactory): Hash = algo.digest { read(it) }

fun InputStream.sha1() = hash(SHA1)

fun InputStream.md4() = hash(MD4)

fun InputStream.md5() = hash(MD5)

fun InputStream.sha256() = hash(SHA256)

fun InputStream.sha512() = hash(SHA512)
```

There is also okio, which provides `Source` and `BufferedSource`:
```kt
fun BufferedSource.hash(algo: HasherFactory): Hash = algo.digest { read(it) }

fun BufferedSource.sha1() = hash(SHA1)

fun BufferedSource.md4() = hash(MD4)

fun BufferedSource.md5() = hash(MD5)

fun BufferedSource.sha256() = hash(SHA256)

fun BufferedSource.sha512() = hash(SHA512)
```

If these could both be included in the jvm only source set, that would be great.
Additionally, extensions for korio can also be included in the common source set.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the existing ByteArray hashing extensions and the JVM-only source set. Check how InputStream and BufferedSource are handled, then consider the requested korio extensions in the common source set. Done means stream hashing extensions exist for the listed algorithms in the applicable source sets and match the existing ByteArray behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
cryptography
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.