Add SHA-1 extension method to ByteBuf

Similar to the existing Whirlpool extension method.

Signed-off-by: Graham <gpe@openrs2.org>
Graham 1 year ago
parent 195ffa7967
commit bba220aebc
  1. 19
      crypto/src/main/kotlin/org/openrs2/crypto/Sha1.kt

@ -0,0 +1,19 @@
package org.openrs2.crypto
import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufUtil
import java.security.MessageDigest
public fun ByteBuf.sha1(): ByteArray {
return sha1(readerIndex(), readableBytes())
}
public fun ByteBuf.sha1(index: Int, len: Int): ByteArray {
val digest = MessageDigest.getInstance("SHA-1")
if (hasArray()) {
digest.update(array(), arrayOffset() + index, len)
} else {
digest.update(ByteBufUtil.getBytes(this, index, len, false))
}
return digest.digest()
}
Loading…
Cancel
Save