mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Added a method for creating local groups.
This commit is contained in:
@@ -9,4 +9,8 @@ public interface GroupFactory {
|
|||||||
|
|
||||||
/** Creates a restricted group. */
|
/** Creates a restricted group. */
|
||||||
Group createGroup(String name, byte[] publicKey) throws IOException;
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.sf.briar.api.crypto.MessageDigest;
|
|||||||
import net.sf.briar.api.messaging.Group;
|
import net.sf.briar.api.messaging.Group;
|
||||||
import net.sf.briar.api.messaging.GroupFactory;
|
import net.sf.briar.api.messaging.GroupFactory;
|
||||||
import net.sf.briar.api.messaging.GroupId;
|
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.Writer;
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
import net.sf.briar.api.serial.WriterFactory;
|
||||||
|
|
||||||
@@ -31,6 +32,17 @@ class GroupFactoryImpl implements GroupFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Group createGroup(String name, byte[] publicKey) throws IOException {
|
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();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeStructId(GROUP);
|
w.writeStructId(GROUP);
|
||||||
@@ -39,7 +51,6 @@ class GroupFactoryImpl implements GroupFactory {
|
|||||||
else w.writeBytes(publicKey);
|
else w.writeBytes(publicKey);
|
||||||
MessageDigest messageDigest = crypto.getMessageDigest();
|
MessageDigest messageDigest = crypto.getMessageDigest();
|
||||||
messageDigest.update(out.toByteArray());
|
messageDigest.update(out.toByteArray());
|
||||||
GroupId id = new GroupId(messageDigest.digest());
|
return new GroupId(messageDigest.digest());
|
||||||
return new Group(id, name, publicKey);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user