• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pgpainless / pgpainless / #1029

pending completion
#1029

push

github-actions

vanitasvitae
Bump BC to 1.76

2 of 2 new or added lines in 1 file covered. (100.0%)

7070 of 7941 relevant lines covered (89.03%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/pgpainless-sop/src/main/java/org/pgpainless/sop/KeyReader.java
1
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
2
//
3
// SPDX-License-Identifier: Apache-2.0
4

5
package org.pgpainless.sop;
6

7
import org.bouncycastle.openpgp.PGPException;
8
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
9
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
10
import org.pgpainless.PGPainless;
11
import sop.exception.SOPGPException;
12

13
import java.io.IOException;
14
import java.io.InputStream;
15

16
/**
17
 * Reader for OpenPGP keys and certificates with error matching according to the SOP spec.
18
 */
19
class KeyReader {
×
20

21
    static PGPSecretKeyRingCollection readSecretKeys(InputStream keyInputStream, boolean requireContent)
22
            throws IOException, SOPGPException.BadData {
23
        PGPSecretKeyRingCollection keys;
24
        try {
25
            keys = PGPainless.readKeyRing().secretKeyRingCollection(keyInputStream);
1✔
26
        } catch (IOException e) {
1✔
27
            String message = e.getMessage();
1✔
28
            if (message == null) {
1✔
29
                throw e;
×
30
            }
31
            if (message.startsWith("unknown object in stream:") ||
1✔
32
                    message.startsWith("invalid header encountered")) {
1✔
33
                throw new SOPGPException.BadData(e);
1✔
34
            }
35
            throw e;
×
36
        }
1✔
37

38
        if (requireContent && keys.size() == 0) {
1✔
39
            throw new SOPGPException.BadData(new PGPException("No key data found."));
1✔
40
        }
41

42
        return keys;
1✔
43
    }
44

45
    static PGPPublicKeyRingCollection readPublicKeys(InputStream certIn, boolean requireContent)
46
            throws IOException {
47
        PGPPublicKeyRingCollection certs;
48
        try {
49
            certs = PGPainless.readKeyRing().publicKeyRingCollection(certIn);
1✔
50
        } catch (IOException e) {
1✔
51
            String msg = e.getMessage();
1✔
52
            if (msg != null && (msg.startsWith("unknown object in stream:") || msg.startsWith("invalid header encountered"))) {
1✔
53
                throw new SOPGPException.BadData(e);
1✔
54
            }
55
            throw e;
×
56
        }
1✔
57
        if (requireContent && certs.size() == 0) {
1✔
58
            throw new SOPGPException.BadData(new PGPException("No cert data found."));
1✔
59
        }
60
        return certs;
1✔
61
    }
62
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc