diff --git a/briar-api/src/net/sf/briar/api/messaging/GroupFactory.java b/briar-api/src/net/sf/briar/api/messaging/GroupFactory.java index dec240777..6fd7b4ab6 100644 --- a/briar-api/src/net/sf/briar/api/messaging/GroupFactory.java +++ b/briar-api/src/net/sf/briar/api/messaging/GroupFactory.java @@ -9,4 +9,8 @@ public interface GroupFactory { /** Creates a restricted group. */ Group createGroup(String name, byte[] publicKey) throws IOException; + + /** Creates a restricted group to which the local user can post messages. */ + LocalGroup createLocalGroup(String name, byte[] publicKey, + byte[] privateKey) throws IOException; } diff --git a/briar-core/src/net/sf/briar/messaging/GroupFactoryImpl.java b/briar-core/src/net/sf/briar/messaging/GroupFactoryImpl.java index a7cf91f13..c32248b8d 100644 --- a/briar-core/src/net/sf/briar/messaging/GroupFactoryImpl.java +++ b/briar-core/src/net/sf/briar/messaging/GroupFactoryImpl.java @@ -10,6 +10,7 @@ import net.sf.briar.api.crypto.MessageDigest; import net.sf.briar.api.messaging.Group; import net.sf.briar.api.messaging.GroupFactory; import net.sf.briar.api.messaging.GroupId; +import net.sf.briar.api.messaging.LocalGroup; import net.sf.briar.api.serial.Writer; import net.sf.briar.api.serial.WriterFactory; @@ -31,6 +32,17 @@ class GroupFactoryImpl implements GroupFactory { } public Group createGroup(String name, byte[] publicKey) throws IOException { + GroupId id = getId(name, publicKey); + return new Group(id, name, publicKey); + } + + public LocalGroup createLocalGroup(String name, byte[] publicKey, + byte[] privateKey) throws IOException { + GroupId id = getId(name, publicKey); + return new LocalGroup(id, name, publicKey, privateKey); + } + + private GroupId getId(String name, byte[] publicKey) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Writer w = writerFactory.createWriter(out); w.writeStructId(GROUP); @@ -39,7 +51,6 @@ class GroupFactoryImpl implements GroupFactory { else w.writeBytes(publicKey); MessageDigest messageDigest = crypto.getMessageDigest(); messageDigest.update(out.toByteArray()); - GroupId id = new GroupId(messageDigest.digest()); - return new Group(id, name, publicKey); + return new GroupId(messageDigest.digest()); } }