forked from openrs2/openrs2
Similar to the existing Whirlpool extension method. Signed-off-by: Graham <gpe@openrs2.org>
parent
195ffa7967
commit
bba220aebc
@ -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…
Reference in new issue