Skip to content

Commit b5d1896

Browse files
committed
Fixed hash utils
1 parent f2fa357 commit b5d1896

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

common/src/main/kotlin/com/lambda/module/modules/player/MapDownloader.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.lambda.module.tag.ModuleTag
2424
import com.lambda.util.FolderRegister
2525
import com.lambda.util.FolderRegister.locationBoundDirectory
2626
import com.lambda.util.StringUtils.hash
27+
import com.lambda.util.StringUtils.hashString
2728
import com.lambda.util.player.SlotUtils.combined
2829
import com.lambda.util.world.entitySearch
2930
import net.minecraft.block.MapColor
@@ -57,7 +58,7 @@ object MapDownloader : Module(
5758
}
5859

5960
private val MapState.hash: String
60-
get() = colors.hash("SHA-256")
61+
get() = colors.hashString("SHA-256")
6162

6263
fun MapState.toBufferedImage(): BufferedImage {
6364
val image = BufferedImage(128, 128, BufferedImage.TYPE_INT_ARGB)

common/src/main/kotlin/com/lambda/util/StringUtils.kt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,29 @@ object StringUtils {
101101
*
102102
* @return The string representation of the hash
103103
*/
104-
fun String.hash(algorithm: String, vararg extra: ByteArray): String =
105-
MessageDigest
106-
.getInstance(algorithm)
107-
.apply { update(toByteArray()); extra.forEach(::update) }
108-
.digest()
104+
fun String.hashString(algorithm: String, vararg extra: ByteArray): String =
105+
toByteArray().hash(algorithm, *extra)
106+
.joinToString(separator = "") { "%02x".format(it) }
107+
108+
/**
109+
* See [MessageDigest section](https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#messagedigest-algorithms) of the Java Security Standard Algorithm Names Specification
110+
*
111+
* @receiver The byte array to hash
112+
* @param algorithm The algorithm instance to use
113+
* @param extra Additional data to digest with the byte array
114+
*
115+
* @return The string representation of the hash
116+
*/
117+
fun ByteArray.hashString(algorithm: String, vararg extra: ByteArray): String =
118+
hash(algorithm, *extra)
109119
.joinToString(separator = "") { "%02x".format(it) }
110120

111121
/**
112122
* See [MessageDigest section](https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#messagedigest-algorithms) of the Java Security Standard Algorithm Names Specification
113123
*
114124
* @receiver The byte array to hash
115125
* @param algorithm The algorithm instance to use
116-
* @param extra Additional data to digest with the bytearray
126+
* @param extra Additional data to digest with the byte array
117127
*
118128
* @return The digested data
119129
*/

0 commit comments

Comments
 (0)