Replace hasArray() and array() logic with ByteBufUtil.getBytes()

bzip2
Graham 5 years ago
parent db11c5536d
commit 531db3159e
  1. 10
      common/src/main/java/dev/openrs2/common/crypto/Rsa.kt

@ -1,6 +1,7 @@
package dev.openrs2.common.crypto
import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufUtil
import io.netty.buffer.Unpooled
import org.bouncycastle.asn1.DERNull
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers
@ -28,14 +29,7 @@ val RSAPrivateCrtKeyParameters.publicKey
get() = RSAKeyParameters(false, modulus, publicExponent)
private fun ByteBuf.toBigInteger(): BigInteger {
val bytes: ByteArray
if (hasArray() && arrayOffset() == 0 && readerIndex() == 0 && readableBytes() == array().size) {
bytes = array()
} else {
bytes = ByteArray(readableBytes())
getBytes(readerIndex(), bytes)
}
val bytes = ByteBufUtil.getBytes(this, readerIndex(), readableBytes(), false)
return BigInteger(bytes)
}

Loading…
Cancel
Save