From 68634e0f28c405e1e5d1d3c86084067715e43f51 Mon Sep 17 00:00:00 2001 From: akwizgran <michael@briarproject.org> Date: Tue, 16 Jan 2018 17:22:35 +0000 Subject: [PATCH] Add helper method for encoding authors. --- .../bramble/api/client/ClientHelper.java | 2 ++ .../bramble/client/ClientHelperImpl.java | 5 +++++ .../bramble/client/ClientHelperImplTest.java | 12 ++++++++++++ 3 files changed, 19 insertions(+) diff --git a/bramble-api/src/main/java/org/briarproject/bramble/api/client/ClientHelper.java b/bramble-api/src/main/java/org/briarproject/bramble/api/client/ClientHelper.java index 814136f4f0..dff1799e7e 100644 --- a/bramble-api/src/main/java/org/briarproject/bramble/api/client/ClientHelper.java +++ b/bramble-api/src/main/java/org/briarproject/bramble/api/client/ClientHelper.java @@ -94,6 +94,8 @@ public interface ClientHelper { BdfList toList(Message m) throws FormatException; + BdfList toList(Author a); + byte[] sign(String label, BdfList toSign, byte[] privateKey) throws FormatException, GeneralSecurityException; diff --git a/bramble-core/src/main/java/org/briarproject/bramble/client/ClientHelperImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/client/ClientHelperImpl.java index 2af115819e..4ced8b3f76 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/client/ClientHelperImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/client/ClientHelperImpl.java @@ -351,6 +351,11 @@ class ClientHelperImpl implements ClientHelper { raw.length - MESSAGE_HEADER_LENGTH); } + @Override + public BdfList toList(Author a) { + return BdfList.of(a.getFormatVersion(), a.getName(), a.getPublicKey()); + } + @Override public byte[] sign(String label, BdfList toSign, byte[] privateKey) throws FormatException, GeneralSecurityException { diff --git a/bramble-core/src/test/java/org/briarproject/bramble/client/ClientHelperImplTest.java b/bramble-core/src/test/java/org/briarproject/bramble/client/ClientHelperImplTest.java index 4ffe9e5326..0d54281a80 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/client/ClientHelperImplTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/client/ClientHelperImplTest.java @@ -331,6 +331,18 @@ public class ClientHelperImplTest extends BrambleTestCase { } } + @Test + public void testParsesAndEncodesAuthor() throws Exception { + context.checking(new Expectations() {{ + oneOf(authorFactory).createAuthor(author.getFormatVersion(), + author.getName(), author.getPublicKey()); + will(returnValue(author)); + }}); + + BdfList authorList = clientHelper.toList(author); + assertEquals(author, clientHelper.parseAndValidateAuthor(authorList)); + } + @Test public void testAcceptsValidAuthor() throws Exception { BdfList authorList = BdfList.of( -- GitLab