1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-15 17:02:06 +01:00

Work on Network

This commit is contained in:
Paul Schaub 2023-07-07 16:37:29 +02:00
parent 4f2f54f4b3
commit 9d6ae1c0bb
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
7 changed files with 46 additions and 17 deletions

View file

@ -16,9 +16,15 @@ import java.util.*
*/
data class CertSynopsis(
val fingerprint: Fingerprint,
val expirationTime: Date?,
val revocationState: RevocationState,
val userIds : Map<String, RevocationState>) {
val expirationTime: Date? = null,
val revocationState: RevocationState = RevocationState.notRevoked(),
val userIds : Map<String, RevocationState> = mapOf()) {
constructor(fingerprint: String,
expirationTime: Date? = null,
revocationState: RevocationState = RevocationState.notRevoked(),
userIds: Map<String, RevocationState> = mapOf()):
this(Fingerprint(fingerprint), expirationTime, revocationState, userIds)
override fun toString(): String {
return if (userIds.isEmpty()) {

View file

@ -43,8 +43,8 @@ data class Certification(
*/
constructor(
issuer: CertSynopsis,
targetUserId: String?,
target: CertSynopsis,
targetUserId: String?,
creationTime: Date) :
this(issuer, target, targetUserId, creationTime, null, true, 120, Depth.limited(0), RegexSet.wildcard())

View file

@ -71,22 +71,25 @@ class Network(
private val protoEdges: MutableMap<Pair<Fingerprint, Fingerprint>, CertificationSet> = mutableMapOf()
private var referenceTime: ReferenceTime = ReferenceTime.now()
fun addNode(node: CertSynopsis) {
fun addNode(node: CertSynopsis): Builder {
nodes[node.fingerprint] = node
return this
}
fun getNode(fingerprint: Fingerprint): CertSynopsis? {
return nodes[fingerprint]
}
fun addEdge(edge: Certification) {
fun addEdge(edge: Certification): Builder {
protoEdges.getOrPut(Pair(edge.issuer.fingerprint, edge.target.fingerprint)) {
CertificationSet.empty(edge.issuer, edge.target)
}.add(edge)
return this
}
fun setReferenceTime(time: ReferenceTime) {
fun setReferenceTime(time: ReferenceTime): Builder {
this.referenceTime = time
return this
}
fun build(): Network {

View file

@ -17,10 +17,10 @@ class CertificationSetTest {
private val bob = CertSynopsis(Fingerprint("B"), null, RevocationState.notRevoked(), mapOf())
private val charlie = CertSynopsis(Fingerprint("C"), null, RevocationState.notRevoked(), mapOf())
private val aliceSignsBob = Certification(alice, null, bob, Date())
private val aliceSignsBobUserId = Certification(alice, "Bob <bob@example.org>", bob, Date())
private val aliceSignsCharlie = Certification(alice, null, charlie, Date())
private val charlieSignsBob = Certification(charlie, null, bob, Date())
private val aliceSignsBob = Certification(alice, bob, null, Date())
private val aliceSignsBobUserId = Certification(alice, bob, "Bob <bob@example.org>", Date())
private val aliceSignsCharlie = Certification(alice, charlie, null, Date())
private val charlieSignsBob = Certification(charlie, bob, null, Date())
@Test
fun `verify that properties of an empty CertificationSet are also empty`() {
@ -112,8 +112,8 @@ class CertificationSetTest {
fun `verify that for multiple Certifications over the same datum, only the most recent certifications are preserved`() {
val now = Date()
val fiveSecondsBefore = Date(now.time - 5000)
val old = Certification(alice, "Bob <bob@example.org>", bob, fiveSecondsBefore)
val new = Certification(alice, "Bob <bob@example.org>", bob, now)
val old = Certification(alice, bob, "Bob <bob@example.org>", fiveSecondsBefore)
val new = Certification(alice, bob, "Bob <bob@example.org>", now)
val new2 = Certification(alice, bob, "Bob <bob@example.org>", now, null, true, 44, Depth.auto(10), RegexSet.wildcard())
var set = CertificationSet(alice, bob, mapOf())

View file

@ -28,21 +28,21 @@ class CertificationTest {
@Test
fun `verify result of toString() on certification`() {
val certification = Certification(alice, "Bob <bob@example.org>", bob, Date())
val certification = Certification(alice, bob, "Bob <bob@example.org>", Date())
assertEquals("A certifies binding: Bob <bob@example.org> <-> B [120]",
certification.toString())
}
@Test
fun `verify result of toString() on delegation`() {
val delegation = Certification(alice, null, bob, Date())
val delegation = Certification(alice, bob, null, Date())
assertEquals("A certifies binding: null <-> B [120]",
delegation.toString())
}
@Test
fun `verify result of toString() on delegation with userId-less issuer`() {
val delegation = Certification(charlie, null, bob, Date())
val delegation = Certification(charlie, bob, null, Date())
assertEquals("C certifies binding: null <-> B [120]",
delegation.toString())
}

View file

@ -5,8 +5,12 @@
package org.pgpainless.wot.dijkstra
import org.junit.jupiter.api.Test
import org.pgpainless.wot.dijkstra.sq.CertSynopsis
import org.pgpainless.wot.dijkstra.sq.Certification
import org.pgpainless.wot.dijkstra.sq.Network
import org.pgpainless.wot.dijkstra.sq.Network.Companion.empty
import org.pgpainless.wot.dijkstra.sq.ReferenceTime.Companion.now
import java.util.Date
import kotlin.test.assertEquals
class NetworkTest {
@ -22,4 +26,20 @@ class NetworkTest {
assertEquals(0, network.numberOfEdges)
assertEquals(0, network.numberOfSignatures)
}
@Test
fun testSimpleNetwork() {
val alice = CertSynopsis("A")
val bob = CertSynopsis("B")
val edge = Certification(alice, bob, null, Date())
val network = Network.builder()
.addNode(alice)
.addNode(bob)
.addEdge(edge)
.build()
println(network)
}
}

View file

@ -32,7 +32,7 @@ class PathTest {
// Alice -(255,255)-> Root
private val alice_root = Certification(alice, root, 255, Depth.unconstrained())
// Alice -(120, 1)-> Bob
private val alice_bob = Certification(alice, null, bob, Date())
private val alice_bob = Certification(alice, bob, null, Date())
// Root -> Root
private val root_root = Certification(root, root, 120, Depth.limited(1))