Compare commits
2 Commits
db7453fbb2
...
7fa3ab1ca8
Author | SHA1 | Date | |
---|---|---|---|
7fa3ab1ca8 | |||
242cc7d0f5 |
@ -9,7 +9,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "net.sergeych"
|
group = "net.sergeych"
|
||||||
version = "0.7.1-SNAPSHOT"
|
version = "0.7.2-SNAPSHOT"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
@ -6,6 +6,7 @@ import net.sergeych.bipack.BipackEncoder
|
|||||||
import net.sergeych.bipack.decodeFromBipack
|
import net.sergeych.bipack.decodeFromBipack
|
||||||
import net.sergeych.crypto2.Seal.Companion.create
|
import net.sergeych.crypto2.Seal.Companion.create
|
||||||
import net.sergeych.utools.now
|
import net.sergeych.utools.now
|
||||||
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extended public-key signature.
|
* Extended public-key signature.
|
||||||
@ -67,7 +68,7 @@ class Seal(
|
|||||||
*/
|
*/
|
||||||
fun verify(message: UByteArray) {
|
fun verify(message: UByteArray) {
|
||||||
val n = now()
|
val n = now()
|
||||||
if (createdAt > n) throw IllegalSignatureException("signature's timestamp in the future")
|
if (createdAt - 45.seconds > n) throw IllegalSignatureException("signature's timestamp in the future: $createdAt / $n")
|
||||||
expiresAt?.let {
|
expiresAt?.let {
|
||||||
if (n >= it) throw ExpiredSignatureException("signature expired at $it")
|
if (n >= it) throw ExpiredSignatureException("signature expired at $it")
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import net.sergeych.bintools.toDump
|
||||||
|
import net.sergeych.bipack.BipackEncoder
|
||||||
import net.sergeych.crypto2.BinaryId
|
import net.sergeych.crypto2.BinaryId
|
||||||
|
import net.sergeych.crypto2.ByteChunk
|
||||||
|
import net.sergeych.crypto2.initCrypto
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertContentEquals
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class BinaryIdTest {
|
class BinaryIdTest {
|
||||||
@ -13,4 +19,16 @@ class BinaryIdTest {
|
|||||||
assertEquals(4, a.id.size)
|
assertEquals(4, a.id.size)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testByteChunkSizes() = runTest {
|
||||||
|
initCrypto()
|
||||||
|
val x = ByteChunk.random(3)
|
||||||
|
assertEquals(3, x.data.size)
|
||||||
|
assertEquals(3, x.toByteArray().size)
|
||||||
|
assertEquals(3, x.toUByteArray().size)
|
||||||
|
println(BipackEncoder.encode(x).toDump())
|
||||||
|
assertEquals(4, BipackEncoder.encode(x).size)
|
||||||
|
assertContentEquals(BipackEncoder.encode(x.toByteArray()), BipackEncoder.encode(x))
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user