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 dec240777b3fe0c7818da19d96432cd902059518..6fd7b4ab611945db9bd5829008ab97182769e4e5 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 a7cf91f133eb9ec7784b2f619dce94ff05944090..c32248b8d482a0e58be7a4cc38609d5ba8063583 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()); } }