fix(DigestUtils): lateinit property not initialize
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package io.legado.app.utils
|
package io.legado.app.utils
|
||||||
|
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
import java.security.NoSuchAlgorithmException
|
|
||||||
import javax.crypto.Mac
|
import javax.crypto.Mac
|
||||||
import javax.crypto.spec.SecretKeySpec
|
import javax.crypto.spec.SecretKeySpec
|
||||||
|
|
||||||
@@ -25,14 +24,10 @@ object DigestUtils {
|
|||||||
algorithm: String,
|
algorithm: String,
|
||||||
data: ByteArray
|
data: ByteArray
|
||||||
): ByteArray {
|
): ByteArray {
|
||||||
lateinit var bytes: ByteArray
|
return kotlin.runCatching {
|
||||||
try {
|
|
||||||
val messageDigest = MessageDigest.getInstance(algorithm)
|
val messageDigest = MessageDigest.getInstance(algorithm)
|
||||||
bytes = messageDigest.digest(data)
|
messageDigest.digest(data)
|
||||||
} catch (e: NoSuchAlgorithmException) {
|
}.getOrThrow()
|
||||||
e.printOnDebug()
|
|
||||||
}
|
|
||||||
return bytes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,17 +50,13 @@ object DigestUtils {
|
|||||||
key: ByteArray,
|
key: ByteArray,
|
||||||
data: ByteArray
|
data: ByteArray
|
||||||
): ByteArray {
|
): ByteArray {
|
||||||
lateinit var bytes: ByteArray
|
return kotlin.runCatching {
|
||||||
try {
|
|
||||||
val mac= Mac.getInstance(algorithm)
|
val mac= Mac.getInstance(algorithm)
|
||||||
val keySpec = SecretKeySpec(key, algorithm)
|
val keySpec = SecretKeySpec(key, algorithm)
|
||||||
mac.init(keySpec)
|
mac.init(keySpec)
|
||||||
mac.update(data)
|
mac.update(data)
|
||||||
bytes = mac.doFinal()
|
mac.doFinal()
|
||||||
} catch(e: NoSuchAlgorithmException) {
|
}.getOrThrow()
|
||||||
e.printOnDebug()
|
|
||||||
}
|
|
||||||
return bytes
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user