Skip to content

Commit

Permalink
Add more hash functions & fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Jun 4, 2022
1 parent 2914613 commit feaba2a
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 33 deletions.
10 changes: 10 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions core/api/stdx-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ public final class dev/schlaubi/stdx/core/CollectionUtilKt {
public static final fun onEach (Ljava/lang/Iterable;Lkotlin/jvm/functions/Function1;)V
}

public final class dev/schlaubi/stdx/core/PathUtilKt {
public static final fun parent (Ljava/nio/file/Path;I)Ljava/nio/file/Path;
}

public final class dev/schlaubi/stdx/core/StringUtilJvm {
public final class dev/schlaubi/stdx/core/HashUtilJvm {
public static final fun hash (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
public static final fun hash ([BLjava/lang/String;)Ljava/lang/String;
public static final fun sha256 (Ljava/lang/String;)Ljava/lang/String;
public static final fun sha256 ([B)Ljava/lang/String;
}

public final class dev/schlaubi/stdx/core/PathUtilKt {
public static final fun parent (Ljava/nio/file/Path;I)Ljava/nio/file/Path;
}

public final class dev/schlaubi/stdx/core/StringUtilKt {
Expand Down
44 changes: 44 additions & 0 deletions core/src/jvmMain/kotlin/dev/schlaubi/stdx/core/HashUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@file:JvmName("HashUtilJvm")

package dev.schlaubi.stdx.core

import java.security.MessageDigest

/**
* Hashes this [String] using `SHA-256`.
*
* @see hash
*/
public fun String.sha256(): String = hash("SHA-256")

/**
* Hashes this [ByteArray] using `SHA-256`.
*
* @see hash
*/
public fun ByteArray.sha256(): String = hash("SHA-256")

/**
* Hashes this [String] using [algorithm].
*
* @param algorithm the algorithm according to
* [the Java spec](https://docs.oracle.com/en/java/javase/18/docs/specs/security/standard-names.html#messagedigest-algorithms)
*
* @see MessageDigest.digest
*/
public fun String.hash(algorithm: String): String = toByteArray().hash(algorithm)

/**
* Hashes this [ByteArray] using [algorithm].
*
* @param algorithm the algorithm according to
* [the Java spec](https://docs.oracle.com/en/java/javase/18/docs/specs/security/standard-names.html#messagedigest-algorithms)
*
* @see MessageDigest.digest
*/
public fun ByteArray.hash(algorithm: String): String {
return MessageDigest
.getInstance(algorithm)
.digest(this)
.fold("") { str, it -> str + "%02x".format(it) }
}
27 changes: 0 additions & 27 deletions core/src/jvmMain/kotlin/dev/schlaubi/stdx/core/StringUtil.kt

This file was deleted.

2 changes: 1 addition & 1 deletion logging/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ kotlin {
api("io.github.microutils", "kotlin-logging", "2.1.21")
}
}
jvmTest {
findByName("jvmTest")?.apply {
dependencies {
implementation("org.slf4j", "slf4j-simple", "1.7.36")
}
Expand Down

0 comments on commit feaba2a

Please sign in to comment.