forked from sergeych/crypto2
+id now has public constructor
+default bas64 repr for ByteChunk
This commit is contained in:
1 parent
cef7e4abed
commit
db7453fbb2
4 files changed
+9
-3
No files matched your search
@@ -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") }
|
||||
|
||||
Reference in new issue
Block a user