mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
Merge branch '1173-qr-code-version' into 'master'
Use first byte of QR code payload for format version Closes #1173 See merge request akwizgran/briar!702
This commit is contained in:
@@ -3,9 +3,9 @@ package org.briarproject.bramble.api.keyagreement;
|
|||||||
public interface KeyAgreementConstants {
|
public interface KeyAgreementConstants {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current version of the BQP protocol.
|
* The current version of the BQP protocol. Version number 89 is reserved.
|
||||||
*/
|
*/
|
||||||
byte PROTOCOL_VERSION = 3;
|
byte PROTOCOL_VERSION = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The length of the record header in bytes.
|
* The length of the record header in bytes.
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ class PayloadEncoderImpl implements PayloadEncoder {
|
|||||||
@Override
|
@Override
|
||||||
public byte[] encode(Payload p) {
|
public byte[] encode(Payload p) {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
out.write(PROTOCOL_VERSION);
|
||||||
BdfWriter w = bdfWriterFactory.createWriter(out);
|
BdfWriter w = bdfWriterFactory.createWriter(out);
|
||||||
try {
|
try {
|
||||||
w.writeListStart(); // Payload start
|
w.writeListStart(); // Payload start
|
||||||
w.writeLong(PROTOCOL_VERSION);
|
|
||||||
w.writeRaw(p.getCommitment());
|
w.writeRaw(p.getCommitment());
|
||||||
for (TransportDescriptor d : p.getTransportDescriptors())
|
for (TransportDescriptor d : p.getTransportDescriptors())
|
||||||
w.writeList(d.getDescriptor());
|
w.writeList(d.getDescriptor());
|
||||||
|
|||||||
@@ -40,22 +40,22 @@ class PayloadParserImpl implements PayloadParser {
|
|||||||
@Override
|
@Override
|
||||||
public Payload parse(byte[] raw) throws IOException {
|
public Payload parse(byte[] raw) throws IOException {
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(raw);
|
ByteArrayInputStream in = new ByteArrayInputStream(raw);
|
||||||
BdfReader r = bdfReaderFactory.createReader(in);
|
// First byte: the protocol version
|
||||||
// The payload is a BDF list with two or more elements
|
int protocolVersion = in.read();
|
||||||
BdfList payload = r.readList();
|
if (protocolVersion == -1) throw new FormatException();
|
||||||
if (payload.size() < 2) throw new FormatException();
|
if (protocolVersion != PROTOCOL_VERSION)
|
||||||
if (!r.eof()) throw new FormatException();
|
|
||||||
// First element: the protocol version
|
|
||||||
long protocolVersion = payload.getLong(0);
|
|
||||||
if (protocolVersion != PROTOCOL_VERSION) {
|
|
||||||
throw new UnsupportedVersionException();
|
throw new UnsupportedVersionException();
|
||||||
}
|
// The rest of the payload is a BDF list with one or more elements
|
||||||
// Second element: the public key commitment
|
BdfReader r = bdfReaderFactory.createReader(in);
|
||||||
byte[] commitment = payload.getRaw(1);
|
BdfList payload = r.readList();
|
||||||
|
if (payload.isEmpty()) throw new FormatException();
|
||||||
|
if (!r.eof()) throw new FormatException();
|
||||||
|
// First element: the public key commitment
|
||||||
|
byte[] commitment = payload.getRaw(0);
|
||||||
if (commitment.length != COMMIT_LENGTH) throw new FormatException();
|
if (commitment.length != COMMIT_LENGTH) throw new FormatException();
|
||||||
// Remaining elements: transport descriptors
|
// Remaining elements: transport descriptors
|
||||||
List<TransportDescriptor> recognised = new ArrayList<>();
|
List<TransportDescriptor> recognised = new ArrayList<>();
|
||||||
for (int i = 2; i < payload.size(); i++) {
|
for (int i = 1; i < payload.size(); i++) {
|
||||||
BdfList descriptor = payload.getList(i);
|
BdfList descriptor = payload.getList(i);
|
||||||
long transportId = descriptor.getLong(0);
|
long transportId = descriptor.getLong(0);
|
||||||
if (transportId == TRANSPORT_ID_BLUETOOTH) {
|
if (transportId == TRANSPORT_ID_BLUETOOTH) {
|
||||||
|
|||||||
Reference in New Issue
Block a user