Cleanup deprecated methods.

Noticed a handful of deprecated methods and minor warnings while looking around.
Replaces with recommended methods
This commit is contained in:
Renee Vandervelde 2024-07-01 20:07:15 -05:00
parent b919de5d71
commit bd3cbb1662
No known key found for this signature in database
GPG Key ID: 1E3B6A09031AACF4
9 changed files with 16 additions and 14 deletions

View File

@ -3,13 +3,15 @@ package com.ionspin.kotlin.crypto
import com.ionspin.kotlin.crypto.hash.MultipartHash import com.ionspin.kotlin.crypto.hash.MultipartHash
import com.ionspin.kotlin.crypto.hash.encodeToUByteArray import com.ionspin.kotlin.crypto.hash.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.toHexString import com.ionspin.kotlin.crypto.util.toHexString
import kotlin.jvm.JvmInline
/** /**
* Created by Ugljesa Jovanovic * Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com * ugljesa.jovanovic@ionspin.com
* on 23-Jun-2020 * on 23-Jun-2020
*/ */
inline class EncryptableString(val content: String) : Encryptable<EncryptableString> { @JvmInline
value class EncryptableString(val content: String) : Encryptable<EncryptableString> {
override fun toEncryptableForm(): UByteArray { override fun toEncryptableForm(): UByteArray {
return content.encodeToUByteArray() return content.encodeToUByteArray()
} }

View File

@ -44,4 +44,4 @@ interface XChaCha20KeyProvider {
fun generateNewKey() : XChaCha20.Key fun generateNewKey() : XChaCha20.Key
fun createFromUByteArray(uByteArray: UByteArray) : XChaCha20.Key fun createFromUByteArray(uByteArray: UByteArray) : XChaCha20.Key
} }

View File

@ -8,13 +8,13 @@ package com.ionspin.kotlin.crypto.util
val _emit = IntArray(0) val _emit = IntArray(0)
fun UByteArray.overwriteWithZeroes() { fun UByteArray.overwriteWithZeroes() {
for (i in 0 until size) { for (i in indices) {
this[i] = 0U this[i] = 0U
} }
} }
fun UIntArray.overwriteWithZeroes() { fun UIntArray.overwriteWithZeroes() {
for (i in 0 until size) { for (i in indices) {
this[i] = 0U this[i] = 0U
} }
} }

View File

@ -7,22 +7,22 @@ package com.ionspin.kotlin.crypto.util
*/ */
fun Array<Byte>.hexColumsPrint() { fun Array<Byte>.hexColumsPrint() {
val printout = this.map { it.toString(16) }.chunked(16) val printout = this.map { it.toString(16) }.chunked(16)
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) } printout.forEach { println(it.joinToString(separator = " ") { it.uppercase() }) }
} }
fun Array<UByte>.hexColumsPrint(chunk : Int = 16) { fun Array<UByte>.hexColumsPrint(chunk : Int = 16) {
val printout = this.map { it.toString(16).padStart(2, '0') }.chunked(chunk) val printout = this.map { it.toString(16).padStart(2, '0') }.chunked(chunk)
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) } printout.forEach { println(it.joinToString(separator = " ") { it.uppercase() }) }
} }
fun UByteArray.hexColumsPrint(chunk : Int = 16) { fun UByteArray.hexColumsPrint(chunk : Int = 16) {
val printout = this.map { it.toString(16).padStart(2, '0') }.chunked(chunk) val printout = this.map { it.toString(16).padStart(2, '0') }.chunked(chunk)
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) } printout.forEach { println(it.joinToString(separator = " ") { it.uppercase() }) }
} }
fun Array<ULong>.hexColumsPrint(chunk: Int = 3) { fun Array<ULong>.hexColumsPrint(chunk: Int = 3) {
val printout = this.map { it.toString(16) }.chunked(chunk) val printout = this.map { it.toString(16) }.chunked(chunk)
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) } printout.forEach { println(it.joinToString(separator = " ") { it.uppercase() }) }
} }
fun String.hexStringToTypedUByteArray() : Array<UByte> { fun String.hexStringToTypedUByteArray() : Array<UByte> {

View File

@ -29,10 +29,10 @@ fun UByteArray.toHexString() : String {
fun Array<UByte>.hexColumnsPrint(chunk: Int = 16) { fun Array<UByte>.hexColumnsPrint(chunk: Int = 16) {
val printout = this.map { it.toString(16).padStart(2, '0') }.chunked(chunk) val printout = this.map { it.toString(16).padStart(2, '0') }.chunked(chunk)
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) } printout.forEach { println(it.joinToString(separator = " ") { it.uppercase() }) }
} }
fun UByteArray.hexColumnsPrint(chunk: Int = 16) { fun UByteArray.hexColumnsPrint(chunk: Int = 16) {
val printout = this.map { it.toString(16).padStart(2, '0') }.chunked(chunk) val printout = this.map { it.toString(16).padStart(2, '0') }.chunked(chunk)
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) } printout.forEach { println(it.joinToString(separator = " ") { it.uppercase() }) }
} }

View File

@ -27,7 +27,7 @@ object JsSodiumLoader {
} }
suspend fun load() = suspendCoroutine<Unit> { continuation -> suspend fun load() = suspendCoroutine { continuation ->
if (!getSodiumLoaded()) { if (!getSodiumLoaded()) {
_libsodiumPromise.then<dynamic> { _libsodiumPromise.then<dynamic> {
sodium_init() sodium_init()

View File

@ -27,7 +27,7 @@ actual object Kdf {
): UByteArray { ): UByteArray {
return getSodium().crypto_kdf_derive_from_key( return getSodium().crypto_kdf_derive_from_key(
subkeyLength.toUInt(), subkeyLength.toUInt(),
subkeyId.toUInt(), subkeyId,
context, context,
masterKey.toUInt8Array() masterKey.toUInt8Array()
).toUByteArray() ).toUByteArray()

View File

@ -8,7 +8,7 @@ import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
actual object PasswordHash { actual object PasswordHash {
/** /**
* The crypto_pwhash() function derives an outlen bytes long key from a password passwd whose length is passwdlen * The crypto_pwhash() function derives an outlen bytes long key from a password passwd whose length is passwdlen
* and a salt salt whose fixed length is crypto_pwhash_SALTBYTES bytes. passwdlen should be at least crypto_pwhash_ * and a salt whose fixed length is crypto_pwhash_SALTBYTES bytes. passwdlen should be at least crypto_pwhash_
* PASSWD_MIN and crypto_pwhash_PASSWD_MAX. outlen should be at least crypto_pwhash_BYTES_MIN = 16 (128 bits) and * PASSWD_MIN and crypto_pwhash_PASSWD_MAX. outlen should be at least crypto_pwhash_BYTES_MIN = 16 (128 bits) and
* at most crypto_pwhash_BYTES_MAX. * at most crypto_pwhash_BYTES_MAX.
* *

View File

@ -93,7 +93,7 @@ actual object LibsodiumUtil {
actual fun fromHex(data: String): UByteArray { actual fun fromHex(data: String): UByteArray {
val binLenReference = IntByReference(0) val binLenReference = IntByReference(0)
val binSize = (data.length + 1) / 2 // -1 for terminator char val binSize = (data.length + 1) / 2 // -1 for terminator char
val hex = data.toCharArray().map { it.toByte() }.toByteArray() val hex = data.toCharArray().map { it.code.toByte() }.toByteArray()
val result = ByteArray(binSize) val result = ByteArray(binSize)
val resultCode = sodiumJna.sodium_hex2bin( val resultCode = sodiumJna.sodium_hex2bin(
result, result,