mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-23 12:52:07 +01:00
InputStreams: overwrite read(b, off, len) for improved performance
This commit is contained in:
parent
5eb470862e
commit
ab951fcf03
2 changed files with 22 additions and 0 deletions
|
@ -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) {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Reference in a new issue