1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-25 04:17:59 +01:00

WIP: Work on PGP-DSL

This commit is contained in:
Paul Schaub 2023-07-07 19:59:02 +02:00
parent 7a1df02920
commit f69d2d20df
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 73 additions and 19 deletions

View file

@ -250,23 +250,6 @@ class WebOfTrust(private val certificateStore: PGPCertificateStore) {
*/ */
private fun Fingerprint(fingerprint: OpenPgpFingerprint) = Fingerprint(fingerprint.toString()) private fun Fingerprint(fingerprint: OpenPgpFingerprint) = Fingerprint(fingerprint.toString())
/**
* Map a [PGPSignature] to its [RevocationState].
*
* @param revocation optional revocation signature
*/
private fun RevocationState(revocation: PGPSignature?): RevocationState {
if (revocation == null) {
return RevocationState.notRevoked()
}
val revocationReason = SignatureSubpacketsUtil.getRevocationReason(revocation)
?: return RevocationState.hardRevoked()
return if (RevocationAttributes.Reason.isHardRevocation(revocationReason.revocationReason))
RevocationState.hardRevoked()
else
RevocationState.softRevoked(revocation.creationTime)
}
/** /**
* Return the constructed, initialized [Network]. * Return the constructed, initialized [Network].
* *
@ -336,4 +319,25 @@ class WebOfTrust(private val certificateStore: PGPCertificateStore) {
} }
} }
} }
companion object {
@JvmStatic
/**
* Map a [PGPSignature] to its [RevocationState].
*
* @param revocation optional revocation signature
*/
fun RevocationState(revocation: PGPSignature?): RevocationState {
if (revocation == null) {
return RevocationState.notRevoked()
}
val revocationReason = SignatureSubpacketsUtil.getRevocationReason(revocation)
?: return RevocationState.hardRevoked()
return if (RevocationAttributes.Reason.isHardRevocation(revocationReason.revocationReason))
RevocationState.hardRevoked()
else
RevocationState.softRevoked(revocation.creationTime)
}
}
} }

View file

@ -2,12 +2,15 @@ package org.pgpainless.wot
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.pgpainless.wot.testfixtures.AdHocVectors import org.pgpainless.wot.testfixtures.AdHocVectors
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class AdHocTest { class AdHocTest: PGPDSL {
@Test @Test
fun test() { fun test() {
val store = AdHocVectors.BestViaRoot().pgpCertificateStore val vectors = AdHocVectors.BestViaRoot()
val store = vectors.pgpCertificateStore
val network = WebOfTrust(store).buildNetwork() val network = WebOfTrust(store).buildNetwork()
} }
} }

View file

@ -0,0 +1,47 @@
package org.pgpainless.wot
import org.bouncycastle.openpgp.PGPPublicKeyRing
import org.bouncycastle.openpgp.PGPSignature
import org.pgpainless.algorithm.RevocationStateType
import org.pgpainless.key.OpenPgpFingerprint
import org.pgpainless.key.info.KeyRingInfo
import org.pgpainless.wot.dijkstra.sq.CertSynopsis
import org.pgpainless.wot.dijkstra.sq.Fingerprint
import org.pgpainless.wot.dijkstra.sq.RevocationState
interface PGPDSL {
fun CertSynopsis(certificate: PGPPublicKeyRing): CertSynopsis {
return CertSynopsis(Fingerprint(certificate), )
}
fun CertSynopsis(validatedCert: KeyRingInfo): CertSynopsis {
return CertSynopsis(
Fingerprint(validatedCert.fingerprint),
validatedCert.primaryKeyExpirationDate,
RevocationState(validatedCert.revocationState),
validatedCert.userIds.associateWith{
RevocationState(validatedCert.getUserIdRevocation(it))
})
}
fun Fingerprint(certificate: PGPPublicKeyRing): Fingerprint {
return Fingerprint(OpenPgpFingerprint.of(certificate))
}
fun Fingerprint(pgpFingerprint: OpenPgpFingerprint): Fingerprint {
return Fingerprint(pgpFingerprint.toString())
}
fun RevocationState(signature: PGPSignature?): RevocationState {
return WebOfTrust.RevocationState(signature)
}
fun RevocationState(pgpRevocationState: org.pgpainless.algorithm.RevocationState): RevocationState {
return when(pgpRevocationState.type) {
RevocationStateType.hardRevoked -> RevocationState.hardRevoked()
RevocationStateType.notRevoked -> RevocationState.notRevoked()
else -> RevocationState.softRevoked(pgpRevocationState.date)
}
}
}