mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Explanatory names for MessageFactory methods.
This commit is contained in:
@@ -7,25 +7,27 @@ import java.security.PrivateKey;
|
||||
public interface MessageFactory {
|
||||
|
||||
/** Creates a private message. */
|
||||
Message createMessage(MessageId parent, String subject, byte[] body)
|
||||
throws IOException, GeneralSecurityException;
|
||||
Message createPrivateMessage(MessageId parent, String subject, byte[] body)
|
||||
throws IOException, GeneralSecurityException;
|
||||
|
||||
/** Creates an anonymous message to an unrestricted group. */
|
||||
Message createMessage(MessageId parent, Group group, String subject,
|
||||
byte[] body) throws IOException, GeneralSecurityException;
|
||||
|
||||
/** Creates an anonymous message to a restricted group. */
|
||||
Message createMessage(MessageId parent, Group group, PrivateKey groupKey,
|
||||
Message createAnonymousGroupMessage(MessageId parent, Group group,
|
||||
String subject, byte[] body) throws IOException,
|
||||
GeneralSecurityException;
|
||||
|
||||
/** Creates an anonymous message to a restricted group. */
|
||||
Message createAnonymousGroupMessage(MessageId parent, Group group,
|
||||
PrivateKey groupKey, String subject, byte[] body)
|
||||
throws IOException, GeneralSecurityException;
|
||||
|
||||
/** Creates a pseudonymous message to an unrestricted group. */
|
||||
Message createMessage(MessageId parent, Group group, Author author,
|
||||
PrivateKey authorKey, String subject, byte[] body)
|
||||
throws IOException, GeneralSecurityException;
|
||||
Message createPseudonymousMessage(MessageId parent, Group group,
|
||||
Author author, PrivateKey authorKey, String subject, byte[] body)
|
||||
throws IOException, GeneralSecurityException;
|
||||
|
||||
/** Creates a pseudonymous message to a restricted group. */
|
||||
Message createMessage(MessageId parent, Group group, PrivateKey groupKey,
|
||||
Author author, PrivateKey authorKey, String subject, byte[] body)
|
||||
throws IOException, GeneralSecurityException;
|
||||
Message createPseudonymousMessage(MessageId parent, Group group,
|
||||
PrivateKey groupKey, Author author, PrivateKey authorKey,
|
||||
String subject, byte[] body) throws IOException,
|
||||
GeneralSecurityException;
|
||||
}
|
||||
|
||||
@@ -52,35 +52,44 @@ class MessageFactoryImpl implements MessageFactory {
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
public Message createMessage(MessageId parent, String subject, byte[] body)
|
||||
throws IOException, GeneralSecurityException {
|
||||
public Message createPrivateMessage(MessageId parent, String subject,
|
||||
byte[] body) throws IOException, GeneralSecurityException {
|
||||
return createMessage(parent, null, null, null, null, subject, body);
|
||||
}
|
||||
|
||||
public Message createMessage(MessageId parent, Group group, String subject,
|
||||
byte[] body) throws IOException, GeneralSecurityException {
|
||||
public Message createAnonymousGroupMessage(MessageId parent, Group group,
|
||||
String subject, byte[] body) throws IOException,
|
||||
GeneralSecurityException {
|
||||
return createMessage(parent, group, null, null, null, subject, body);
|
||||
}
|
||||
|
||||
public Message createMessage(MessageId parent, Group group,
|
||||
public Message createAnonymousGroupMessage(MessageId parent, Group group,
|
||||
PrivateKey groupKey, String subject, byte[] body)
|
||||
throws IOException, GeneralSecurityException {
|
||||
throws IOException, GeneralSecurityException {
|
||||
return createMessage(parent, group, groupKey, null, null, subject,
|
||||
body);
|
||||
}
|
||||
|
||||
public Message createMessage(MessageId parent, Group group, Author author,
|
||||
PrivateKey authorKey, String subject, byte[] body)
|
||||
throws IOException, GeneralSecurityException {
|
||||
public Message createPseudonymousMessage(MessageId parent, Group group,
|
||||
Author author, PrivateKey authorKey, String subject, byte[] body)
|
||||
throws IOException, GeneralSecurityException {
|
||||
return createMessage(parent, group, null, author, authorKey, subject,
|
||||
body);
|
||||
}
|
||||
|
||||
public Message createMessage(MessageId parent, Group group,
|
||||
public Message createPseudonymousMessage(MessageId parent, Group group,
|
||||
PrivateKey groupKey, Author author, PrivateKey authorKey,
|
||||
String subject, byte[] body) throws IOException,
|
||||
GeneralSecurityException {
|
||||
return createMessage(parent, group, groupKey, author, authorKey,
|
||||
subject, body);
|
||||
}
|
||||
|
||||
private Message createMessage(MessageId parent, Group group,
|
||||
PrivateKey groupKey, Author author, PrivateKey authorKey,
|
||||
String subject, byte[] body) throws IOException,
|
||||
GeneralSecurityException {
|
||||
// Validate the arguments
|
||||
if((author == null) != (authorKey == null))
|
||||
throw new IllegalArgumentException();
|
||||
if((group == null || group.getPublicKey() == null)
|
||||
@@ -90,7 +99,7 @@ class MessageFactoryImpl implements MessageFactory {
|
||||
throw new IllegalArgumentException();
|
||||
if(body.length > MAX_BODY_LENGTH)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
// Serialise the message to a buffer
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
Writer w = writerFactory.createWriter(out);
|
||||
// Initialise the consumers
|
||||
|
||||
@@ -106,15 +106,15 @@ public class ProtocolIntegrationTest extends BriarTestCase {
|
||||
authorKeyPair.getPublic().getEncoded());
|
||||
// Create two messages to each group: one anonymous, one pseudonymous
|
||||
MessageFactory messageFactory = i.getInstance(MessageFactory.class);
|
||||
message = messageFactory.createMessage(null, group, subject,
|
||||
messageBody.getBytes("UTF-8"));
|
||||
message1 = messageFactory.createMessage(null, group1,
|
||||
message = messageFactory.createAnonymousGroupMessage(null, group,
|
||||
subject, messageBody.getBytes("UTF-8"));
|
||||
message1 = messageFactory.createAnonymousGroupMessage(null, group1,
|
||||
groupKeyPair.getPrivate(), subject,
|
||||
messageBody.getBytes("UTF-8"));
|
||||
message2 = messageFactory.createMessage(null, group, author,
|
||||
authorKeyPair.getPrivate(), subject,
|
||||
message2 = messageFactory.createPseudonymousMessage(null, group,
|
||||
author, authorKeyPair.getPrivate(), subject,
|
||||
messageBody.getBytes("UTF-8"));
|
||||
message3 = messageFactory.createMessage(null, group1,
|
||||
message3 = messageFactory.createPseudonymousMessage(null, group1,
|
||||
groupKeyPair.getPrivate(), author, authorKeyPair.getPrivate(),
|
||||
subject, messageBody.getBytes("UTF-8"));
|
||||
messageIds = Arrays.asList(message.getId(), message1.getId(),
|
||||
|
||||
@@ -109,6 +109,7 @@ public class ConstantsTest extends BriarTestCase {
|
||||
|
||||
@Test
|
||||
public void testMessageFitsIntoPacket() throws Exception {
|
||||
MessageId parent = new MessageId(TestUtils.getRandomId());
|
||||
// Create a maximum-length group
|
||||
String groupName = createRandomString(MAX_GROUP_NAME_LENGTH);
|
||||
byte[] groupPublic = new byte[MAX_PUBLIC_KEY_LENGTH];
|
||||
@@ -124,8 +125,8 @@ public class ConstantsTest extends BriarTestCase {
|
||||
crypto.generateSignatureKeyPair().getPrivate();
|
||||
String subject = createRandomString(MAX_SUBJECT_LENGTH);
|
||||
byte[] body = new byte[MAX_BODY_LENGTH];
|
||||
Message message = messageFactory.createMessage(null, group,
|
||||
groupPrivate, author, authorPrivate, subject, body);
|
||||
Message message = messageFactory.createPseudonymousMessage(parent,
|
||||
group, groupPrivate, author, authorPrivate, subject, body);
|
||||
// Check the size of the serialised message
|
||||
int length = message.getSerialised().length;
|
||||
assertTrue(length > UniqueId.LENGTH + MAX_GROUP_NAME_LENGTH
|
||||
|
||||
@@ -115,7 +115,8 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
|
||||
String subject = "Hello";
|
||||
byte[] body = "Hi Bob!".getBytes("UTF-8");
|
||||
MessageFactory messageFactory = alice.getInstance(MessageFactory.class);
|
||||
Message message = messageFactory.createMessage(null, subject, body);
|
||||
Message message = messageFactory.createPrivateMessage(null, subject,
|
||||
body);
|
||||
db.addLocalPrivateMessage(message, contactId);
|
||||
// Create an outgoing simplex connection
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
||||
Reference in New Issue
Block a user