From 98064e9efe4c7ca533ccc40d518db8b5faa78a41 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Sat, 18 Feb 2023 16:24:21 +0000 Subject: [PATCH] Remove BdfWriter methods for manually constructing lists and dicts. --- .../bramble/api/data/BdfWriter.java | 8 ------ .../bramble/data/BdfWriterImpl.java | 20 -------------- .../keyagreement/PayloadEncoderImpl.java | 12 +++++---- .../bramble/data/BdfWriterImplTest.java | 27 ------------------- 4 files changed, 7 insertions(+), 60 deletions(-) diff --git a/bramble-api/src/main/java/org/briarproject/bramble/api/data/BdfWriter.java b/bramble-api/src/main/java/org/briarproject/bramble/api/data/BdfWriter.java index 8e0e11d73..1427859a6 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/api/data/BdfWriter.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/api/data/BdfWriter.java @@ -24,13 +24,5 @@ public interface BdfWriter { void writeList(Collection c) throws IOException; - void writeListStart() throws IOException; - - void writeListEnd() throws IOException; - void writeDictionary(Map m) throws IOException; - - void writeDictionaryStart() throws IOException; - - void writeDictionaryEnd() throws IOException; } diff --git a/bramble-core/src/main/java/org/briarproject/bramble/data/BdfWriterImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/data/BdfWriterImpl.java index 13812d6c1..263f7bdde 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/data/BdfWriterImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/data/BdfWriterImpl.java @@ -168,16 +168,6 @@ final class BdfWriterImpl implements BdfWriter { else throw new FormatException(); } - @Override - public void writeListStart() throws IOException { - out.write(LIST); - } - - @Override - public void writeListEnd() throws IOException { - out.write(END); - } - @Override public void writeDictionary(Map m) throws IOException { out.write(DICTIONARY); @@ -194,14 +184,4 @@ final class BdfWriterImpl implements BdfWriter { } out.write(END); } - - @Override - public void writeDictionaryStart() throws IOException { - out.write(DICTIONARY); - } - - @Override - public void writeDictionaryEnd() throws IOException { - out.write(END); - } } diff --git a/bramble-core/src/main/java/org/briarproject/bramble/keyagreement/PayloadEncoderImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/keyagreement/PayloadEncoderImpl.java index ca90f5f96..86b4109fe 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/keyagreement/PayloadEncoderImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/keyagreement/PayloadEncoderImpl.java @@ -1,5 +1,6 @@ package org.briarproject.bramble.keyagreement; +import org.briarproject.bramble.api.data.BdfList; import org.briarproject.bramble.api.data.BdfWriter; import org.briarproject.bramble.api.data.BdfWriterFactory; import org.briarproject.bramble.api.keyagreement.Payload; @@ -32,13 +33,14 @@ class PayloadEncoderImpl implements PayloadEncoder { ByteArrayOutputStream out = new ByteArrayOutputStream(); int formatIdAndVersion = (QR_FORMAT_ID << 5) | QR_FORMAT_VERSION; out.write(formatIdAndVersion); + BdfList payload = new BdfList(); + payload.add(p.getCommitment()); + for (TransportDescriptor d : p.getTransportDescriptors()) { + payload.add(d.getDescriptor()); + } BdfWriter w = bdfWriterFactory.createWriter(out); try { - w.writeListStart(); // Payload start - w.writeRaw(p.getCommitment()); - for (TransportDescriptor d : p.getTransportDescriptors()) - w.writeList(d.getDescriptor()); - w.writeListEnd(); // Payload end + w.writeList(payload); } catch (IOException e) { // Shouldn't happen with ByteArrayOutputStream throw new AssertionError(e); diff --git a/bramble-core/src/test/java/org/briarproject/bramble/data/BdfWriterImplTest.java b/bramble-core/src/test/java/org/briarproject/bramble/data/BdfWriterImplTest.java index d643a9b62..6a4e9cdb6 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/data/BdfWriterImplTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/data/BdfWriterImplTest.java @@ -179,33 +179,6 @@ public class BdfWriterImplTest extends BrambleTestCase { "41" + "01" + "33" + "21" + "03" + "80"); } - @Test - public void testWriteDelimitedList() throws IOException { - w.writeListStart(); - w.writeLong(1); - w.writeString("foo"); - w.writeLong(128); - w.writeListEnd(); - // LIST tag, 1 as integer, "foo" as string, 128 as integer, END tag - checkContents("60" + "21" + "01" + - "41" + "03" + "666F6F" + - "22" + "0080" + "80"); - } - - @Test - public void testWriteDelimitedDictionary() throws IOException { - w.writeDictionaryStart(); - w.writeString("foo"); - w.writeLong(123); - w.writeString("bar"); - w.writeNull(); - w.writeDictionaryEnd(); - // DICTIONARY tag, "foo" as string, 123 as integer, "bar" as string, - // NULL tag, END tag - checkContents("70" + "41" + "03" + "666F6F" + - "21" + "7B" + "41" + "03" + "626172" + "00" + "80"); - } - @Test public void testWriteNestedDictionariesAndLists() throws IOException { Map inner = new LinkedHashMap<>();