Fixed NPE when 'from' doesn't have a public key. From will get lost in those cases unless it's saved separately.

This commit is contained in:
Christian Basler 2016-12-05 07:41:55 +01:00
parent 0bb455d433
commit 31eca20cca

View File

@ -178,6 +178,16 @@ public class Plaintext implements Streamable {
public void write(OutputStream out, boolean includeSignature) throws IOException { public void write(OutputStream out, boolean includeSignature) throws IOException {
Encode.varInt(from.getVersion(), out); Encode.varInt(from.getVersion(), out);
Encode.varInt(from.getStream(), out); Encode.varInt(from.getStream(), out);
if (from.getPubkey() == null) {
Encode.int32(0, out);
byte[] empty = new byte[64];
out.write(empty);
out.write(empty);
if (from.getVersion() >= 3) {
Encode.varInt(0, out);
Encode.varInt(0, out);
}
} else {
Encode.int32(from.getPubkey().getBehaviorBitfield(), out); Encode.int32(from.getPubkey().getBehaviorBitfield(), out);
out.write(from.getPubkey().getSigningKey(), 1, 64); out.write(from.getPubkey().getSigningKey(), 1, 64);
out.write(from.getPubkey().getEncryptionKey(), 1, 64); out.write(from.getPubkey().getEncryptionKey(), 1, 64);
@ -185,6 +195,7 @@ public class Plaintext implements Streamable {
Encode.varInt(from.getPubkey().getNonceTrialsPerByte(), out); Encode.varInt(from.getPubkey().getNonceTrialsPerByte(), out);
Encode.varInt(from.getPubkey().getExtraBytes(), out); Encode.varInt(from.getPubkey().getExtraBytes(), out);
} }
}
if (type == Type.MSG) { if (type == Type.MSG) {
out.write(to.getRipe()); out.write(to.getRipe());
} }
@ -213,6 +224,16 @@ public class Plaintext implements Streamable {
public void write(ByteBuffer buffer, boolean includeSignature) { public void write(ByteBuffer buffer, boolean includeSignature) {
Encode.varInt(from.getVersion(), buffer); Encode.varInt(from.getVersion(), buffer);
Encode.varInt(from.getStream(), buffer); Encode.varInt(from.getStream(), buffer);
if (from.getPubkey() == null) {
Encode.int32(0, buffer);
byte[] empty = new byte[64];
buffer.put(empty);
buffer.put(empty);
if (from.getVersion() >= 3) {
Encode.varInt(0, buffer);
Encode.varInt(0, buffer);
}
} else {
Encode.int32(from.getPubkey().getBehaviorBitfield(), buffer); Encode.int32(from.getPubkey().getBehaviorBitfield(), buffer);
buffer.put(from.getPubkey().getSigningKey(), 1, 64); buffer.put(from.getPubkey().getSigningKey(), 1, 64);
buffer.put(from.getPubkey().getEncryptionKey(), 1, 64); buffer.put(from.getPubkey().getEncryptionKey(), 1, 64);
@ -220,6 +241,7 @@ public class Plaintext implements Streamable {
Encode.varInt(from.getPubkey().getNonceTrialsPerByte(), buffer); Encode.varInt(from.getPubkey().getNonceTrialsPerByte(), buffer);
Encode.varInt(from.getPubkey().getExtraBytes(), buffer); Encode.varInt(from.getPubkey().getExtraBytes(), buffer);
} }
}
if (type == Type.MSG) { if (type == Type.MSG) {
buffer.put(to.getRipe()); buffer.put(to.getRipe());
} }