mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
fix: UUID string format #1421
This commit is contained in:
@@ -20,9 +20,10 @@
|
|||||||
package com.kunzisoft.keepass.credentialprovider.passkey.data
|
package com.kunzisoft.keepass.credentialprovider.passkey.data
|
||||||
|
|
||||||
import com.kunzisoft.keepass.credentialprovider.passkey.util.Base64Helper.Companion.b64Encode
|
import com.kunzisoft.keepass.credentialprovider.passkey.util.Base64Helper.Companion.b64Encode
|
||||||
import com.kunzisoft.keepass.utils.UUIDUtils.asUUIDBytes
|
import com.kunzisoft.keepass.utils.UUIDUtils.asBytes
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
class AuthenticatorAttestationResponse(
|
class AuthenticatorAttestationResponse(
|
||||||
private val requestOptions: PublicKeyCredentialCreationOptions,
|
private val requestOptions: PublicKeyCredentialCreationOptions,
|
||||||
@@ -83,6 +84,6 @@ class AuthenticatorAttestationResponse(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// Authenticator Attestation Global Unique Identifier
|
// Authenticator Attestation Global Unique Identifier
|
||||||
private val AAGUID: ByteArray = "eaecdef2-1c31-5634-8639-f1cbd9c00a08".asUUIDBytes()
|
private val AAGUID: ByteArray = UUID.fromString("eaecdef2-1c31-5634-8639-f1cbd9c00a08").asBytes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,6 +24,10 @@ import java.util.Locale
|
|||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
object UUIDUtils {
|
object UUIDUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specific UUID string format for KeePass database
|
||||||
|
*/
|
||||||
fun UUID.asHexString(): String? {
|
fun UUID.asHexString(): String? {
|
||||||
try {
|
try {
|
||||||
val buf = uuidTo16Bytes(this)
|
val buf = uuidTo16Bytes(this)
|
||||||
@@ -52,6 +56,10 @@ object UUIDUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* From a specific UUID KeePass database string format,
|
||||||
|
* Note : For a standard UUID string format, use UUID.fromString()
|
||||||
|
*/
|
||||||
fun String.asUUID(): UUID? {
|
fun String.asUUID(): UUID? {
|
||||||
if (this.length != 32) return null
|
if (this.length != 32) return null
|
||||||
|
|
||||||
@@ -98,10 +106,6 @@ object UUIDUtils {
|
|||||||
}.array()
|
}.array()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.asUUIDBytes(): ByteArray {
|
|
||||||
return this.asUUID()?.asBytes() ?: ByteArray(16)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use short to represent unsigned byte
|
// Use short to represent unsigned byte
|
||||||
private fun byteToChar(bt: Char): Char {
|
private fun byteToChar(bt: Char): Char {
|
||||||
return if (bt.code >= 10) {
|
return if (bt.code >= 10) {
|
||||||
|
|||||||
@@ -27,13 +27,19 @@ import java.util.UUID
|
|||||||
|
|
||||||
class UUIDTest: TestCase() {
|
class UUIDTest: TestCase() {
|
||||||
|
|
||||||
fun testUUIDString() {
|
fun testUUIDHexString() {
|
||||||
val randomUUID = UUID.randomUUID()
|
val randomUUID = UUID.randomUUID()
|
||||||
val hexStringUUID = randomUUID.asHexString()
|
val hexStringUUID = randomUUID.asHexString()
|
||||||
val retrievedUUID = hexStringUUID?.asUUID()
|
val retrievedUUID = hexStringUUID?.asUUID()
|
||||||
assertEquals(randomUUID, retrievedUUID)
|
assertEquals(randomUUID, retrievedUUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testUUIDString() {
|
||||||
|
val staticUUID = "4be0643f-1d98-573b-97cd-ca98a65347dd"
|
||||||
|
val stringUUID = UUID.fromString(staticUUID).asBytes().asUUID().toString()
|
||||||
|
assertEquals(staticUUID, stringUUID)
|
||||||
|
}
|
||||||
|
|
||||||
fun testUUIDBytes() {
|
fun testUUIDBytes() {
|
||||||
val randomUUID = UUID.randomUUID()
|
val randomUUID = UUID.randomUUID()
|
||||||
val byteArrayUUID = randomUUID.asBytes()
|
val byteArrayUUID = randomUUID.asBytes()
|
||||||
|
|||||||
Reference in New Issue
Block a user