mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-24 11:57:59 +01:00
Work on Network
This commit is contained in:
parent
f880fb94aa
commit
fce8634e4e
7 changed files with 46 additions and 17 deletions
|
@ -16,9 +16,15 @@ import java.util.*
|
||||||
*/
|
*/
|
||||||
data class CertSynopsis(
|
data class CertSynopsis(
|
||||||
val fingerprint: Fingerprint,
|
val fingerprint: Fingerprint,
|
||||||
val expirationTime: Date?,
|
val expirationTime: Date? = null,
|
||||||
val revocationState: RevocationState,
|
val revocationState: RevocationState = RevocationState.notRevoked(),
|
||||||
val userIds : Map<String, RevocationState>) {
|
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 {
|
override fun toString(): String {
|
||||||
return if (userIds.isEmpty()) {
|
return if (userIds.isEmpty()) {
|
||||||
|
|
|
@ -43,8 +43,8 @@ data class Certification(
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
issuer: CertSynopsis,
|
issuer: CertSynopsis,
|
||||||
targetUserId: String?,
|
|
||||||
target: CertSynopsis,
|
target: CertSynopsis,
|
||||||
|
targetUserId: String?,
|
||||||
creationTime: Date) :
|
creationTime: Date) :
|
||||||
this(issuer, target, targetUserId, creationTime, null, true, 120, Depth.limited(0), RegexSet.wildcard())
|
this(issuer, target, targetUserId, creationTime, null, true, 120, Depth.limited(0), RegexSet.wildcard())
|
||||||
|
|
||||||
|
|
|
@ -71,22 +71,25 @@ class Network(
|
||||||
private val protoEdges: MutableMap<Pair<Fingerprint, Fingerprint>, CertificationSet> = mutableMapOf()
|
private val protoEdges: MutableMap<Pair<Fingerprint, Fingerprint>, CertificationSet> = mutableMapOf()
|
||||||
private var referenceTime: ReferenceTime = ReferenceTime.now()
|
private var referenceTime: ReferenceTime = ReferenceTime.now()
|
||||||
|
|
||||||
fun addNode(node: CertSynopsis) {
|
fun addNode(node: CertSynopsis): Builder {
|
||||||
nodes[node.fingerprint] = node
|
nodes[node.fingerprint] = node
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getNode(fingerprint: Fingerprint): CertSynopsis? {
|
fun getNode(fingerprint: Fingerprint): CertSynopsis? {
|
||||||
return nodes[fingerprint]
|
return nodes[fingerprint]
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addEdge(edge: Certification) {
|
fun addEdge(edge: Certification): Builder {
|
||||||
protoEdges.getOrPut(Pair(edge.issuer.fingerprint, edge.target.fingerprint)) {
|
protoEdges.getOrPut(Pair(edge.issuer.fingerprint, edge.target.fingerprint)) {
|
||||||
CertificationSet.empty(edge.issuer, edge.target)
|
CertificationSet.empty(edge.issuer, edge.target)
|
||||||
}.add(edge)
|
}.add(edge)
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setReferenceTime(time: ReferenceTime) {
|
fun setReferenceTime(time: ReferenceTime): Builder {
|
||||||
this.referenceTime = time
|
this.referenceTime = time
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun build(): Network {
|
fun build(): Network {
|
||||||
|
|
|
@ -17,10 +17,10 @@ class CertificationSetTest {
|
||||||
private val bob = CertSynopsis(Fingerprint("B"), null, RevocationState.notRevoked(), mapOf())
|
private val bob = CertSynopsis(Fingerprint("B"), null, RevocationState.notRevoked(), mapOf())
|
||||||
private val charlie = CertSynopsis(Fingerprint("C"), null, RevocationState.notRevoked(), mapOf())
|
private val charlie = CertSynopsis(Fingerprint("C"), null, RevocationState.notRevoked(), mapOf())
|
||||||
|
|
||||||
private val aliceSignsBob = Certification(alice, null, bob, Date())
|
private val aliceSignsBob = Certification(alice, bob, null, Date())
|
||||||
private val aliceSignsBobUserId = Certification(alice, "Bob <bob@example.org>", bob, Date())
|
private val aliceSignsBobUserId = Certification(alice, bob, "Bob <bob@example.org>", Date())
|
||||||
private val aliceSignsCharlie = Certification(alice, null, charlie, Date())
|
private val aliceSignsCharlie = Certification(alice, charlie, null, Date())
|
||||||
private val charlieSignsBob = Certification(charlie, null, bob, Date())
|
private val charlieSignsBob = Certification(charlie, bob, null, Date())
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `verify that properties of an empty CertificationSet are also empty`() {
|
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`() {
|
fun `verify that for multiple Certifications over the same datum, only the most recent certifications are preserved`() {
|
||||||
val now = Date()
|
val now = Date()
|
||||||
val fiveSecondsBefore = Date(now.time - 5000)
|
val fiveSecondsBefore = Date(now.time - 5000)
|
||||||
val old = Certification(alice, "Bob <bob@example.org>", bob, fiveSecondsBefore)
|
val old = Certification(alice, bob, "Bob <bob@example.org>", fiveSecondsBefore)
|
||||||
val new = Certification(alice, "Bob <bob@example.org>", bob, now)
|
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())
|
val new2 = Certification(alice, bob, "Bob <bob@example.org>", now, null, true, 44, Depth.auto(10), RegexSet.wildcard())
|
||||||
|
|
||||||
var set = CertificationSet(alice, bob, mapOf())
|
var set = CertificationSet(alice, bob, mapOf())
|
||||||
|
|
|
@ -28,21 +28,21 @@ class CertificationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `verify result of toString() on certification`() {
|
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]",
|
assertEquals("A certifies binding: Bob <bob@example.org> <-> B [120]",
|
||||||
certification.toString())
|
certification.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `verify result of toString() on delegation`() {
|
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]",
|
assertEquals("A certifies binding: null <-> B [120]",
|
||||||
delegation.toString())
|
delegation.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `verify result of toString() on delegation with userId-less issuer`() {
|
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]",
|
assertEquals("C certifies binding: null <-> B [120]",
|
||||||
delegation.toString())
|
delegation.toString())
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,12 @@
|
||||||
package org.pgpainless.wot.dijkstra
|
package org.pgpainless.wot.dijkstra
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test
|
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.Network.Companion.empty
|
||||||
import org.pgpainless.wot.dijkstra.sq.ReferenceTime.Companion.now
|
import org.pgpainless.wot.dijkstra.sq.ReferenceTime.Companion.now
|
||||||
|
import java.util.Date
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class NetworkTest {
|
class NetworkTest {
|
||||||
|
@ -22,4 +26,20 @@ class NetworkTest {
|
||||||
assertEquals(0, network.numberOfEdges)
|
assertEquals(0, network.numberOfEdges)
|
||||||
assertEquals(0, network.numberOfSignatures)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -32,7 +32,7 @@ class PathTest {
|
||||||
// Alice -(255,255)-> Root
|
// Alice -(255,255)-> Root
|
||||||
private val alice_root = Certification(alice, root, 255, Depth.unconstrained())
|
private val alice_root = Certification(alice, root, 255, Depth.unconstrained())
|
||||||
// Alice -(120, 1)-> Bob
|
// Alice -(120, 1)-> Bob
|
||||||
private val alice_bob = Certification(alice, null, bob, Date())
|
private val alice_bob = Certification(alice, bob, null, Date())
|
||||||
// Root -> Root
|
// Root -> Root
|
||||||
private val root_root = Certification(root, root, 120, Depth.limited(1))
|
private val root_root = Certification(root, root, 120, Depth.limited(1))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue