mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-05 03:55:58 +01:00
WIP: Work on PGP-DSL
This commit is contained in:
parent
7a1df02920
commit
f69d2d20df
3 changed files with 73 additions and 19 deletions
|
@ -250,23 +250,6 @@ class WebOfTrust(private val certificateStore: PGPCertificateStore) {
|
|||
*/
|
||||
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].
|
||||
*
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,15 @@ package org.pgpainless.wot
|
|||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.pgpainless.wot.testfixtures.AdHocVectors
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class AdHocTest {
|
||||
class AdHocTest: PGPDSL {
|
||||
|
||||
@Test
|
||||
fun test() {
|
||||
val store = AdHocVectors.BestViaRoot().pgpCertificateStore
|
||||
val vectors = AdHocVectors.BestViaRoot()
|
||||
val store = vectors.pgpCertificateStore
|
||||
val network = WebOfTrust(store).buildNetwork()
|
||||
}
|
||||
}
|
47
pgpainless-wot/src/test/kotlin/org/pgpainless/wot/PGPDSL.kt
Normal file
47
pgpainless-wot/src/test/kotlin/org/pgpainless/wot/PGPDSL.kt
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue