1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-24 11:57:59 +01:00

Rewrite CertSynopsis in Kotlin

This commit is contained in:
Paul Schaub 2023-06-28 13:40:03 +02:00
parent c4ccfd672d
commit 936718b09d
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 22 additions and 82 deletions

View file

@ -1,80 +0,0 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.wot.dijkstra.sq;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.pgpainless.algorithm.RevocationState;
import org.pgpainless.key.OpenPgpFingerprint;
public class CertSynopsis {
private final OpenPgpFingerprint fingerprint;
private final Date expirationTime;
private final RevocationState revocationState;
private final Map<String, RevocationState> userIds;
/**
* Create a new {@link CertSynopsis}.
*
* @param fingerprint fingerprint of the certificate
* @param expirationTime expiration time
* @param revocationState revocation state of the certificate
* @param userIds set of user-ids
*/
public CertSynopsis(OpenPgpFingerprint fingerprint,
Date expirationTime,
RevocationState revocationState,
Map<String, RevocationState> userIds) {
this.fingerprint = fingerprint;
this.expirationTime = expirationTime;
this.revocationState = revocationState;
this.userIds = userIds;
}
/**
* Return the fingerprint of the certificate.
*
* @return fingerprint
*/
public OpenPgpFingerprint getFingerprint() {
return fingerprint;
}
/**
* Get the certificates expiration time.
*
* @return expiration time
*/
public Date getExpirationTime() {
return expirationTime;
}
/**
* Get the revocation status of the certificate.
*
* @return revocation state
*/
public RevocationState getRevocationState() {
return revocationState;
}
/**
* Get a {@link Set} containing all user-ids of the certificate.
*
* @return user-ids
*/
public Map<String, RevocationState> userIds() {
return new HashMap<>(userIds);
}
@Override
public String toString() {
return fingerprint + (userIds.isEmpty() ? "" : "(" + userIds.keySet().iterator().next() + ")");
}
}

View file

@ -140,9 +140,9 @@ public class Certification {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(issuer.getFingerprint()).append((issuer.userIds().isEmpty() ? " " : " (" + issuer.userIds().keySet().iterator().next() + ") "));
sb.append(issuer.getFingerprint()).append((issuer.getUserIds().isEmpty() ? " " : " (" + issuer.getUserIds().keySet().iterator().next() + ") "));
sb.append(userId.isPresent() ? "certifies" : "delegates to").append(userId.isPresent() ? " [" + userId.get() + "] " : " ").append(target.getFingerprint())
.append(userId.isEmpty() && !target.userIds().isEmpty() ? " (" + target.userIds().keySet().iterator().next() + ")" : "");
.append(userId.isEmpty() && !target.getUserIds().isEmpty() ? " (" + target.getUserIds().keySet().iterator().next() + ")" : "");
return sb.toString();
}
}

View file

@ -0,0 +1,20 @@
package org.pgpainless.wot.dijkstra.sq
import org.pgpainless.algorithm.RevocationState
import org.pgpainless.key.OpenPgpFingerprint
import java.util.*
data class CertSynopsis(
val fingerprint: OpenPgpFingerprint,
val expirationTime: Date?,
val revocationState: RevocationState,
val userIds : Map<String, RevocationState>) {
override fun toString(): String {
return if (userIds.isEmpty()) {
"$fingerprint"
} else {
"$fingerprint (${userIds.keys.first()})"
}
}
}