mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-16 17:32:06 +01:00
Add read(b,off,len)
This commit is contained in:
parent
a921f0b85e
commit
0bf85c32c0
1 changed files with 50 additions and 21 deletions
|
@ -38,14 +38,12 @@ import org.pgpainless.implementation.ImplementationFactory;
|
||||||
import org.pgpainless.key.info.KeyRingInfo;
|
import org.pgpainless.key.info.KeyRingInfo;
|
||||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||||
import org.pgpainless.key.protection.UnlockSecretKey;
|
import org.pgpainless.key.protection.UnlockSecretKey;
|
||||||
import org.pgpainless.signature.consumer.DetachedSignatureCheck;
|
|
||||||
import org.pgpainless.util.Passphrase;
|
import org.pgpainless.util.Passphrase;
|
||||||
import org.pgpainless.util.Tuple;
|
import org.pgpainless.util.Tuple;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -88,6 +86,7 @@ public class OpenPgpMessageInputStream extends InputStream {
|
||||||
*/
|
*/
|
||||||
private void consumePackets()
|
private void consumePackets()
|
||||||
throws IOException, PGPException {
|
throws IOException, PGPException {
|
||||||
|
System.out.println("Walk " + automaton);
|
||||||
int tag;
|
int tag;
|
||||||
loop: while ((tag = bcpgIn.nextPacketTag()) != -1) {
|
loop: while ((tag = bcpgIn.nextPacketTag()) != -1) {
|
||||||
OpenPgpPacket nextPacket = OpenPgpPacket.requireFromTag(tag);
|
OpenPgpPacket nextPacket = OpenPgpPacket.requireFromTag(tag);
|
||||||
|
@ -313,15 +312,19 @@ public class OpenPgpMessageInputStream extends InputStream {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read() throws IOException {
|
public int read() throws IOException {
|
||||||
int r = -1;
|
if (in == null) {
|
||||||
if (in != null) {
|
automaton.assertValid();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int r;
|
||||||
try {
|
try {
|
||||||
r = in.read();
|
r = in.read();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
//
|
r = -1;
|
||||||
}
|
}
|
||||||
}
|
boolean eos = r == -1;
|
||||||
if (r != -1) {
|
if (!eos) {
|
||||||
byte b = (byte) r;
|
byte b = (byte) r;
|
||||||
signatures.update(b);
|
signatures.update(b);
|
||||||
} else {
|
} else {
|
||||||
|
@ -330,7 +333,32 @@ public class OpenPgpMessageInputStream extends InputStream {
|
||||||
in = null;
|
in = null;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
System.out.println("Walk " + automaton);
|
System.out.println("Read consume");
|
||||||
|
consumePackets();
|
||||||
|
} catch (PGPException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read(byte[] b, int off, int len)
|
||||||
|
throws IOException {
|
||||||
|
|
||||||
|
if (in == null) {
|
||||||
|
automaton.assertValid();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int r = in.read(b, off, len);
|
||||||
|
if (r == -1) {
|
||||||
|
if (in instanceof OpenPgpMessageInputStream) {
|
||||||
|
in.close();
|
||||||
|
in = null;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
consumePackets();
|
consumePackets();
|
||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -343,6 +371,7 @@ public class OpenPgpMessageInputStream extends InputStream {
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
if (closed) {
|
if (closed) {
|
||||||
|
automaton.assertValid();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue