+id now has public constructor
+default bas64 repr for ByteChunk
This commit is contained in:
parent
cef7e4abed
commit
db7453fbb2
@ -37,7 +37,7 @@ import kotlin.random.Random
|
||||
* @throws InvalidException if crc check failed
|
||||
*/
|
||||
@Serializable
|
||||
open class BinaryId protected constructor (
|
||||
open class BinaryId(
|
||||
/**
|
||||
* The packed binary id. Note that serialized version is one byte longer containing
|
||||
* the size prefix
|
||||
|
@ -53,7 +53,7 @@ class ByteChunk(val data: UByteArray): Comparable<ByteChunk> {
|
||||
/**
|
||||
* hex representation of data
|
||||
*/
|
||||
override fun toString(): String = hex
|
||||
override fun toString(): String = base64Url
|
||||
|
||||
/**
|
||||
* Hex encoded data
|
||||
|
@ -83,7 +83,10 @@ class VerifyingPublicKey(override val keyBytes: UByteArray) : UniversalKey(), Ve
|
||||
val data = s.decodeBase64Url().asUByteArray()
|
||||
if (data.size == 32)
|
||||
VerifyingPublicKey(data)
|
||||
else {
|
||||
else if( data.size == 34) {
|
||||
// raw id
|
||||
BinaryId(data).asVerifyingKey as VerifyingPublicKey
|
||||
}else {
|
||||
runCatching { data.decodeFromBipack<VerifyingPublicKey>() }.getOrNull()
|
||||
?: kotlin.runCatching { data.decodeFromBipack<UniversalKey>() as VerifyingPublicKey }
|
||||
.getOrElse { throw IllegalArgumentException("can't parse verifying key") }
|
||||
|
@ -456,5 +456,8 @@ class KeysTest {
|
||||
testToString(k4)
|
||||
|
||||
for( i in listOf(k1, k2, k3, k4, k5, k6, k7, k8)) testAsString(i)
|
||||
|
||||
val x = VerifyingPublicKey.parse("I1po9Y2I7p2aOxeh4nFyGPm3e0YunBEu1Mo-PmIqP84Evg")
|
||||
println(x)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user