Mark KeyRingReader.read*KeyRing() as @Nullable/@Nonnull

This commit is contained in:
Paul Schaub 2023-05-16 16:26:52 +02:00
parent 1bf9abbdaf
commit d3ae02f137
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
1 changed files with 31 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPKeyRing;
@ -41,6 +42,7 @@ public class KeyRingReader {
* @return key ring
* @throws IOException in case of an IO error
*/
@Nullable
public PGPKeyRing keyRing(@Nonnull InputStream inputStream)
throws IOException {
return readKeyRing(inputStream);
@ -54,6 +56,7 @@ public class KeyRingReader {
* @return key ring
* @throws IOException in case of an IO error
*/
@Nullable
public PGPKeyRing keyRing(@Nonnull byte[] bytes)
throws IOException {
return keyRing(new ByteArrayInputStream(bytes));
@ -67,81 +70,97 @@ public class KeyRingReader {
* @return key ring
* @throws IOException in case of an IO error
*/
@Nullable
public PGPKeyRing keyRing(@Nonnull String asciiArmored)
throws IOException {
return keyRing(asciiArmored.getBytes(UTF8));
}
@Nullable
public PGPPublicKeyRing publicKeyRing(@Nonnull InputStream inputStream)
throws IOException {
return readPublicKeyRing(inputStream);
}
@Nullable
public PGPPublicKeyRing publicKeyRing(@Nonnull byte[] bytes)
throws IOException {
return publicKeyRing(new ByteArrayInputStream(bytes));
}
@Nullable
public PGPPublicKeyRing publicKeyRing(@Nonnull String asciiArmored)
throws IOException {
return publicKeyRing(asciiArmored.getBytes(UTF8));
}
@Nonnull
public PGPPublicKeyRingCollection publicKeyRingCollection(@Nonnull InputStream inputStream)
throws IOException {
return readPublicKeyRingCollection(inputStream);
}
@Nonnull
public PGPPublicKeyRingCollection publicKeyRingCollection(@Nonnull byte[] bytes)
throws IOException {
return publicKeyRingCollection(new ByteArrayInputStream(bytes));
}
@Nonnull
public PGPPublicKeyRingCollection publicKeyRingCollection(@Nonnull String asciiArmored)
throws IOException, PGPException {
throws IOException {
return publicKeyRingCollection(asciiArmored.getBytes(UTF8));
}
@Nullable
public PGPSecretKeyRing secretKeyRing(@Nonnull InputStream inputStream)
throws IOException {
return readSecretKeyRing(inputStream);
}
@Nullable
public PGPSecretKeyRing secretKeyRing(@Nonnull byte[] bytes)
throws IOException {
return secretKeyRing(new ByteArrayInputStream(bytes));
}
@Nullable
public PGPSecretKeyRing secretKeyRing(@Nonnull String asciiArmored)
throws IOException {
return secretKeyRing(asciiArmored.getBytes(UTF8));
}
@Nonnull
public PGPSecretKeyRingCollection secretKeyRingCollection(@Nonnull InputStream inputStream)
throws IOException {
return readSecretKeyRingCollection(inputStream);
}
@Nonnull
public PGPSecretKeyRingCollection secretKeyRingCollection(@Nonnull byte[] bytes)
throws IOException {
return secretKeyRingCollection(new ByteArrayInputStream(bytes));
}
@Nonnull
public PGPSecretKeyRingCollection secretKeyRingCollection(@Nonnull String asciiArmored)
throws IOException {
return secretKeyRingCollection(asciiArmored.getBytes(UTF8));
}
@Nonnull
public PGPKeyRingCollection keyRingCollection(@Nonnull InputStream inputStream, boolean isSilent)
throws IOException, PGPException {
return readKeyRingCollection(inputStream, isSilent);
}
@Nonnull
public PGPKeyRingCollection keyRingCollection(@Nonnull byte[] bytes, boolean isSilent)
throws IOException, PGPException {
return keyRingCollection(new ByteArrayInputStream(bytes), isSilent);
}
@Nonnull
public PGPKeyRingCollection keyRingCollection(@Nonnull String asciiArmored, boolean isSilent)
throws IOException, PGPException {
return keyRingCollection(asciiArmored.getBytes(UTF8), isSilent);
@ -157,6 +176,7 @@ public class KeyRingReader {
* @return key ring
* @throws IOException in case of an IO error
*/
@Nullable
public static PGPKeyRing readKeyRing(@Nonnull InputStream inputStream)
throws IOException {
return readKeyRing(inputStream, MAX_ITERATIONS);
@ -173,6 +193,7 @@ public class KeyRingReader {
* @return key ring
* @throws IOException in case of an IO error
*/
@Nullable
public static PGPKeyRing readKeyRing(@Nonnull InputStream inputStream, int maxIterations)
throws IOException {
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(
@ -198,6 +219,7 @@ public class KeyRingReader {
throw new IOException("Loop exceeded max iteration count.");
}
@Nullable
public static PGPPublicKeyRing readPublicKeyRing(@Nonnull InputStream inputStream)
throws IOException {
return readPublicKeyRing(inputStream, MAX_ITERATIONS);
@ -214,6 +236,7 @@ public class KeyRingReader {
*
* @throws IOException in case of an IO error or exceeding of max iterations
*/
@Nullable
public static PGPPublicKeyRing readPublicKeyRing(@Nonnull InputStream inputStream, int maxIterations)
throws IOException {
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(
@ -236,6 +259,7 @@ public class KeyRingReader {
throw new IOException("Loop exceeded max iteration count.");
}
@Nonnull
public static PGPPublicKeyRingCollection readPublicKeyRingCollection(@Nonnull InputStream inputStream)
throws IOException {
return readPublicKeyRingCollection(inputStream, MAX_ITERATIONS);
@ -252,6 +276,7 @@ public class KeyRingReader {
*
* @throws IOException in case of an IO error or exceeding of max iterations
*/
@Nonnull
public static PGPPublicKeyRingCollection readPublicKeyRingCollection(@Nonnull InputStream inputStream, int maxIterations)
throws IOException {
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(
@ -283,6 +308,7 @@ public class KeyRingReader {
throw new IOException("Loop exceeded max iteration count.");
}
@Nullable
public static PGPSecretKeyRing readSecretKeyRing(@Nonnull InputStream inputStream)
throws IOException {
return readSecretKeyRing(inputStream, MAX_ITERATIONS);
@ -299,6 +325,7 @@ public class KeyRingReader {
*
* @throws IOException in case of an IO error or exceeding of max iterations
*/
@Nullable
public static PGPSecretKeyRing readSecretKeyRing(@Nonnull InputStream inputStream, int maxIterations)
throws IOException {
InputStream decoderStream = ArmorUtils.getDecoderStream(inputStream);
@ -322,6 +349,7 @@ public class KeyRingReader {
throw new IOException("Loop exceeded max iteration count.");
}
@Nonnull
public static PGPSecretKeyRingCollection readSecretKeyRingCollection(@Nonnull InputStream inputStream)
throws IOException {
return readSecretKeyRingCollection(inputStream, MAX_ITERATIONS);
@ -338,6 +366,7 @@ public class KeyRingReader {
*
* @throws IOException in case of an IO error or exceeding of max iterations
*/
@Nonnull
public static PGPSecretKeyRingCollection readSecretKeyRingCollection(@Nonnull InputStream inputStream,
int maxIterations)
throws IOException {
@ -370,6 +399,7 @@ public class KeyRingReader {
throw new IOException("Loop exceeded max iteration count.");
}
@Nonnull
public static PGPKeyRingCollection readKeyRingCollection(@Nonnull InputStream inputStream, boolean isSilent)
throws IOException, PGPException {
return new PGPKeyRingCollection(inputStream, isSilent);