Add helper method for encoding authors.

This commit is contained in:
akwizgran
2018-01-16 17:22:35 +00:00
parent 1d81110fe5
commit 68634e0f28
3 changed files with 19 additions and 0 deletions

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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(