Added a method for creating local groups.

This commit is contained in:
akwizgran
2013-04-12 10:26:01 +01:00
parent 2dd163c17a
commit 398f752c34
2 changed files with 17 additions and 2 deletions

View File

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

View File

@@ -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());
}
}