InputStreams: overwrite read(b, off, len) for improved performance

This commit is contained in:
Paul Schaub 2021-08-15 15:32:16 +02:00
parent 5eb470862e
commit ab951fcf03
2 changed files with 22 additions and 0 deletions

View File

@ -60,6 +60,21 @@ public class DecryptionStream extends InputStream {
return r;
}
@Override
public int read(@Nonnull byte[] bytes, int offset, int length) throws IOException {
int read = inputStream.read(bytes, offset, length);
if (read != -1) {
maybeUpdateDetachedSignatures(bytes, offset, read);
}
return read;
}
private void maybeUpdateDetachedSignatures(byte[] bytes, int offset, int length) {
for (DetachedSignature s : resultBuilder.getDetachedSignatures()) {
s.getSignature().update(bytes, offset, length);
}
}
private void maybeUpdateDetachedSignatures(int rByte) {
for (DetachedSignature s : resultBuilder.getDetachedSignatures()) {
if (rByte != -1) {

View File

@ -18,6 +18,8 @@ package org.pgpainless.util;
import java.io.IOException;
import java.io.InputStream;
import javax.annotation.Nonnull;
import org.bouncycastle.openpgp.PGPEncryptedData;
import org.bouncycastle.openpgp.PGPException;
import org.pgpainless.exception.ModificationDetectionException;
@ -37,6 +39,11 @@ public class IntegrityProtectedInputStream extends InputStream {
return inputStream.read();
}
@Override
public int read(@Nonnull byte[] b, int offset, int length) throws IOException {
return inputStream.read(b, offset, length);
}
@Override
public void close() throws IOException {
if (encryptedData.isIntegrityProtected()) {