From 398f752c34f8a90bf1d73b60069a41a2c02e55fa Mon Sep 17 00:00:00 2001 From: akwizgran <michael@briarproject.org> Date: Fri, 12 Apr 2013 10:26:01 +0100 Subject: [PATCH] Added a method for creating local groups. --- .../net/sf/briar/api/messaging/GroupFactory.java | 4 ++++ .../net/sf/briar/messaging/GroupFactoryImpl.java | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) 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 dec240777b..6fd7b4ab61 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 a7cf91f133..c32248b8d4 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()); } } -- GitLab