From 811625c051fbf7524fb59b5b00bcfcd728e5c432 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Fri, 19 May 2017 20:12:21 +0200 Subject: [PATCH] Fixed write(ByteBuffer) --- .../bitmessage/entity/payload/V3Pubkey.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/ch/dissem/bitmessage/entity/payload/V3Pubkey.java b/core/src/main/java/ch/dissem/bitmessage/entity/payload/V3Pubkey.java index 72358d0..5260060 100644 --- a/core/src/main/java/ch/dissem/bitmessage/entity/payload/V3Pubkey.java +++ b/core/src/main/java/ch/dissem/bitmessage/entity/payload/V3Pubkey.java @@ -22,6 +22,7 @@ import ch.dissem.bitmessage.utils.Encode; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Objects; @@ -48,21 +49,28 @@ public class V3Pubkey extends V2Pubkey { public static V3Pubkey read(InputStream is, long stream) throws IOException { return new V3Pubkey.Builder() - .stream(stream) - .behaviorBitfield(Decode.int32(is)) - .publicSigningKey(Decode.bytes(is, 64)) - .publicEncryptionKey(Decode.bytes(is, 64)) - .nonceTrialsPerByte(Decode.varInt(is)) - .extraBytes(Decode.varInt(is)) - .signature(Decode.varBytes(is)) - .build(); + .stream(stream) + .behaviorBitfield(Decode.int32(is)) + .publicSigningKey(Decode.bytes(is, 64)) + .publicEncryptionKey(Decode.bytes(is, 64)) + .nonceTrialsPerByte(Decode.varInt(is)) + .extraBytes(Decode.varInt(is)) + .signature(Decode.varBytes(is)) + .build(); } @Override public void write(OutputStream out) throws IOException { writeBytesToSign(out); - Encode.varInt(signature.length, out); - out.write(signature); + Encode.varBytes(signature, out); + } + + @Override + public void write(ByteBuffer buffer) { + super.write(buffer); + Encode.varInt(nonceTrialsPerByte, buffer); + Encode.varInt(extraBytes, buffer); + Encode.varBytes(signature, buffer); } @Override @@ -104,11 +112,11 @@ public class V3Pubkey extends V2Pubkey { if (o == null || getClass() != o.getClass()) return false; V3Pubkey pubkey = (V3Pubkey) o; return Objects.equals(nonceTrialsPerByte, pubkey.nonceTrialsPerByte) && - Objects.equals(extraBytes, pubkey.extraBytes) && - stream == pubkey.stream && - behaviorBitfield == pubkey.behaviorBitfield && - Arrays.equals(publicSigningKey, pubkey.publicSigningKey) && - Arrays.equals(publicEncryptionKey, pubkey.publicEncryptionKey); + Objects.equals(extraBytes, pubkey.extraBytes) && + stream == pubkey.stream && + behaviorBitfield == pubkey.behaviorBitfield && + Arrays.equals(publicSigningKey, pubkey.publicSigningKey) && + Arrays.equals(publicEncryptionKey, pubkey.publicEncryptionKey); } @Override