Compare commits

..

2 Commits

Author SHA1 Message Date
7fa3ab1ca8 seal now allows up to 45s in future to tolerate some time difference 2025-02-03 17:13:28 +03:00
242cc7d0f5 more tests 2024-11-29 15:42:54 +07:00
3 changed files with 21 additions and 2 deletions

View File

@ -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()

View File

@ -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")
} }

View File

@ -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))
}
} }