mirror of
https://codeberg.org/PGPainless/wkd-java.git
synced 2024-11-15 20:42:05 +01:00
40 lines
1.6 KiB
Java
40 lines
1.6 KiB
Java
|
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
||
|
//
|
||
|
// SPDX-License-Identifier: Apache-2.0
|
||
|
|
||
|
package pgp.wkd.cli;
|
||
|
|
||
|
import org.bouncycastle.openpgp.PGPException;
|
||
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||
|
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
||
|
import org.pgpainless.PGPainless;
|
||
|
import org.pgpainless.certificate_store.CertificateFactory;
|
||
|
import org.pgpainless.key.info.KeyRingInfo;
|
||
|
import pgp.certificate_store.Certificate;
|
||
|
import pgp.wkd.CertificateAndUserIds;
|
||
|
import pgp.wkd.CertificateReader;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
public class CertificateReaderImpl implements CertificateReader {
|
||
|
@Override
|
||
|
public List<CertificateAndUserIds> read(InputStream inputStream) throws IOException {
|
||
|
List<CertificateAndUserIds> certificatesAndUserIds = new ArrayList<>();
|
||
|
try {
|
||
|
PGPPublicKeyRingCollection certificates = PGPainless.readKeyRing().publicKeyRingCollection(inputStream);
|
||
|
for (PGPPublicKeyRing certificate : certificates) {
|
||
|
KeyRingInfo info = PGPainless.inspectKeyRing(certificate);
|
||
|
Certificate parsedCert = CertificateFactory.certificateFromPublicKeyRing(certificate);
|
||
|
List<String> userIds = info.getValidAndExpiredUserIds();
|
||
|
certificatesAndUserIds.add(new CertificateAndUserIds(parsedCert, userIds));
|
||
|
}
|
||
|
return certificatesAndUserIds;
|
||
|
} catch (PGPException e) {
|
||
|
throw new IOException("Cannot parse certificates.", e);
|
||
|
}
|
||
|
}
|
||
|
}
|