Fixed write(ByteBuffer)

This commit is contained in:
Christian Basler 2017-05-19 20:12:21 +02:00
parent 869d2e0386
commit 811625c051

View File

@ -22,6 +22,7 @@ import ch.dissem.bitmessage.utils.Encode;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
@ -48,21 +49,28 @@ public class V3Pubkey extends V2Pubkey {
public static V3Pubkey read(InputStream is, long stream) throws IOException { public static V3Pubkey read(InputStream is, long stream) throws IOException {
return new V3Pubkey.Builder() return new V3Pubkey.Builder()
.stream(stream) .stream(stream)
.behaviorBitfield(Decode.int32(is)) .behaviorBitfield(Decode.int32(is))
.publicSigningKey(Decode.bytes(is, 64)) .publicSigningKey(Decode.bytes(is, 64))
.publicEncryptionKey(Decode.bytes(is, 64)) .publicEncryptionKey(Decode.bytes(is, 64))
.nonceTrialsPerByte(Decode.varInt(is)) .nonceTrialsPerByte(Decode.varInt(is))
.extraBytes(Decode.varInt(is)) .extraBytes(Decode.varInt(is))
.signature(Decode.varBytes(is)) .signature(Decode.varBytes(is))
.build(); .build();
} }
@Override @Override
public void write(OutputStream out) throws IOException { public void write(OutputStream out) throws IOException {
writeBytesToSign(out); writeBytesToSign(out);
Encode.varInt(signature.length, out); Encode.varBytes(signature, out);
out.write(signature); }
@Override
public void write(ByteBuffer buffer) {
super.write(buffer);
Encode.varInt(nonceTrialsPerByte, buffer);
Encode.varInt(extraBytes, buffer);
Encode.varBytes(signature, buffer);
} }
@Override @Override
@ -104,11 +112,11 @@ public class V3Pubkey extends V2Pubkey {
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
V3Pubkey pubkey = (V3Pubkey) o; V3Pubkey pubkey = (V3Pubkey) o;
return Objects.equals(nonceTrialsPerByte, pubkey.nonceTrialsPerByte) && return Objects.equals(nonceTrialsPerByte, pubkey.nonceTrialsPerByte) &&
Objects.equals(extraBytes, pubkey.extraBytes) && Objects.equals(extraBytes, pubkey.extraBytes) &&
stream == pubkey.stream && stream == pubkey.stream &&
behaviorBitfield == pubkey.behaviorBitfield && behaviorBitfield == pubkey.behaviorBitfield &&
Arrays.equals(publicSigningKey, pubkey.publicSigningKey) && Arrays.equals(publicSigningKey, pubkey.publicSigningKey) &&
Arrays.equals(publicEncryptionKey, pubkey.publicEncryptionKey); Arrays.equals(publicEncryptionKey, pubkey.publicEncryptionKey);
} }
@Override @Override