Preliminaries for private group invitation protocol.

This commit is contained in:
akwizgran
2016-11-08 15:44:23 +00:00
parent 32f0b53d15
commit edbf5ff5b4
21 changed files with 179 additions and 84 deletions

View File

@@ -1,25 +1,28 @@
package org.briarproject.api.clients;
import org.briarproject.api.data.BdfDictionary;
import org.briarproject.api.sync.BaseMessageContext;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.MessageId;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
public class BdfMessageContext extends BaseMessageContext {
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class BdfMessageContext {
private final BdfDictionary dictionary;
private final Collection<MessageId> dependencies;
public BdfMessageContext(@NotNull BdfDictionary dictionary,
@NotNull Collection<MessageId> dependencies) {
super(dependencies);
public BdfMessageContext(BdfDictionary dictionary,
Collection<MessageId> dependencies) {
this.dictionary = dictionary;
this.dependencies = dependencies;
}
public BdfMessageContext(@NotNull BdfDictionary dictionary) {
public BdfMessageContext(BdfDictionary dictionary) {
this(dictionary, Collections.<MessageId>emptyList());
}
@@ -27,4 +30,7 @@ public class BdfMessageContext extends BaseMessageContext {
return dictionary;
}
public Collection<MessageId> getDependencies() {
return dependencies;
}
}

View File

@@ -5,14 +5,17 @@ import org.briarproject.api.data.BdfDictionary;
import org.briarproject.api.data.BdfList;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.InvalidMessageException;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageId;
import java.security.GeneralSecurityException;
import java.util.Map;
import javax.annotation.Nullable;
@NotNullByDefault
public interface ClientHelper {
void addLocalMessage(Message m, BdfDictionary metadata, boolean shared)
@@ -21,14 +24,21 @@ public interface ClientHelper {
void addLocalMessage(Transaction txn, Message m, BdfDictionary metadata,
boolean shared) throws DbException, FormatException;
Message createMessage(GroupId g, long timestamp, BdfDictionary body)
throws FormatException;
Message createMessage(GroupId g, long timestamp, BdfList body)
throws FormatException;
Message createMessageForStoringMetadata(GroupId g);
@Nullable
Message getMessage(MessageId m) throws DbException;
@Nullable
Message getMessage(Transaction txn, MessageId m) throws DbException;
@Nullable
BdfList getMessageAsList(MessageId m) throws DbException, FormatException;
@Nullable
BdfList getMessageAsList(Transaction txn, MessageId m) throws DbException,
FormatException;
@@ -80,6 +90,8 @@ public interface ClientHelper {
BdfList toList(byte[] b) throws FormatException;
BdfList toList(Message m) throws FormatException;
byte[] sign(BdfList toSign, byte[] privateKey)
throws FormatException, GeneralSecurityException;

View File

@@ -2,7 +2,6 @@ package org.briarproject.api.clients;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.Group;
import org.jetbrains.annotations.NotNull;
import javax.annotation.concurrent.Immutable;
@@ -13,7 +12,7 @@ public abstract class NamedGroup extends BaseGroup {
private final String name;
private final byte[] salt;
public NamedGroup(@NotNull Group group, @NotNull String name, byte[] salt) {
public NamedGroup(Group group, String name, byte[] salt) {
super(group);
this.name = name;
this.salt = salt;

View File

@@ -6,6 +6,8 @@ import org.briarproject.api.FormatException;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;
import javax.annotation.Nullable;
public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
public static final Object NULL_VALUE = new Object();
@@ -39,6 +41,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
throw new FormatException();
}
@Nullable
public Boolean getOptionalBoolean(String key) throws FormatException {
Object o = get(key);
if (o == null || o == NULL_VALUE) return null;
@@ -61,6 +64,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
throw new FormatException();
}
@Nullable
public Long getOptionalLong(String key) throws FormatException {
Object o = get(key);
if (o == null || o == NULL_VALUE) return null;
@@ -87,6 +91,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
throw new FormatException();
}
@Nullable
public Double getOptionalDouble(String key) throws FormatException {
Object o = get(key);
if (o == null || o == NULL_VALUE) return null;
@@ -108,6 +113,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
throw new FormatException();
}
@Nullable
public String getOptionalString(String key) throws FormatException {
Object o = get(key);
if (o == null || o == NULL_VALUE) return null;
@@ -128,6 +134,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
throw new FormatException();
}
@Nullable
public byte[] getOptionalRaw(String key) throws FormatException {
Object o = get(key);
if (o == null || o == NULL_VALUE) return null;
@@ -149,6 +156,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
throw new FormatException();
}
@Nullable
public BdfList getOptionalList(String key) throws FormatException {
Object o = get(key);
if (o == null || o == NULL_VALUE) return null;
@@ -168,6 +176,7 @@ public class BdfDictionary extends ConcurrentSkipListMap<String, Object> {
throw new FormatException();
}
@Nullable
public BdfDictionary getOptionalDictionary(String key)
throws FormatException {
Object o = get(key);

View File

@@ -2,6 +2,7 @@ package org.briarproject.api.data;
import org.briarproject.api.Bytes;
import org.briarproject.api.FormatException;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.List;
@@ -40,6 +41,7 @@ public class BdfList extends Vector<Object> {
throw new FormatException();
}
@Nullable
public Boolean getOptionalBoolean(int index) throws FormatException {
if (!isInRange(index)) throw new FormatException();
Object o = get(index);
@@ -65,6 +67,7 @@ public class BdfList extends Vector<Object> {
throw new FormatException();
}
@Nullable
public Long getOptionalLong(int index) throws FormatException {
if (!isInRange(index)) throw new FormatException();
Object o = get(index);
@@ -94,6 +97,7 @@ public class BdfList extends Vector<Object> {
throw new FormatException();
}
@Nullable
public Double getOptionalDouble(int index) throws FormatException {
if (!isInRange(index)) throw new FormatException();
Object o = get(index);
@@ -118,6 +122,7 @@ public class BdfList extends Vector<Object> {
throw new FormatException();
}
@Nullable
public String getOptionalString(int index) throws FormatException {
if (!isInRange(index)) throw new FormatException();
Object o = get(index);
@@ -141,6 +146,7 @@ public class BdfList extends Vector<Object> {
throw new FormatException();
}
@Nullable
public byte[] getOptionalRaw(int index) throws FormatException {
if (!isInRange(index)) throw new FormatException();
Object o = get(index);
@@ -165,6 +171,7 @@ public class BdfList extends Vector<Object> {
throw new FormatException();
}
@Nullable
public BdfList getOptionalList(int index) throws FormatException {
if (!isInRange(index)) throw new FormatException();
Object o = get(index);
@@ -187,6 +194,7 @@ public class BdfList extends Vector<Object> {
throw new FormatException();
}
@Nullable
public BdfDictionary getOptionalDictionary(int index)
throws FormatException {
if (!isInRange(index)) throw new FormatException();

View File

@@ -6,13 +6,12 @@ import org.briarproject.api.sharing.InvitationResponse;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ForumInvitationResponse extends InvitationResponse {
public ForumInvitationResponse(@NotNull MessageId id, SessionId sessionId,
GroupId groupId, ContactId contactId, boolean accept, long time, boolean local,
boolean sent, boolean seen, boolean read) {
GroupId groupId, ContactId contactId, boolean accept, long time,
boolean local, boolean sent, boolean seen, boolean read) {
super(id, sessionId, groupId, contactId, accept, time, local, sent,
seen, read);

View File

@@ -3,10 +3,12 @@ package org.briarproject.api.privategroup;
import org.briarproject.api.crypto.CryptoExecutor;
import org.briarproject.api.identity.Author;
import org.briarproject.api.identity.LocalAuthor;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
import org.jetbrains.annotations.Nullable;
@NotNullByDefault
public interface GroupMessageFactory {
/**

View File

@@ -5,7 +5,6 @@ import org.briarproject.api.identity.Author;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sharing.Shareable;
import org.briarproject.api.sync.Group;
import org.jetbrains.annotations.NotNull;
import javax.annotation.concurrent.Immutable;
@@ -15,8 +14,7 @@ public class PrivateGroup extends NamedGroup implements Shareable {
private final Author author;
public PrivateGroup(@NotNull Group group, @NotNull String name,
@NotNull Author author, @NotNull byte[] salt) {
public PrivateGroup(Group group, String name, Author author, byte[] salt) {
super(group, name, salt);
this.author = author;
}

View File

@@ -2,21 +2,20 @@ package org.briarproject.api.privategroup;
import org.briarproject.api.FormatException;
import org.briarproject.api.identity.Author;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.sync.Group;
import org.jetbrains.annotations.NotNull;
@NotNullByDefault
public interface PrivateGroupFactory {
/**
* Creates a private group with the given name and author.
*/
@NotNull
PrivateGroup createPrivateGroup(String name, Author author);
/**
* Creates a private group with the given name, author and salt.
*/
@NotNull
PrivateGroup createPrivateGroup(String name, Author author, byte[] salt);
/**

View File

@@ -1,19 +0,0 @@
package org.briarproject.api.sync;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
public abstract class BaseMessageContext {
private final Collection<MessageId> dependencies;
public BaseMessageContext(@NotNull Collection<MessageId> dependencies) {
this.dependencies = dependencies;
}
public Collection<MessageId> getDependencies() {
return dependencies;
}
}

View File

@@ -1,23 +1,27 @@
package org.briarproject.api.sync;
import org.briarproject.api.db.Metadata;
import org.jetbrains.annotations.NotNull;
import org.briarproject.api.nullsafety.NotNullByDefault;
import java.util.Collection;
import java.util.Collections;
public class MessageContext extends BaseMessageContext {
import javax.annotation.concurrent.Immutable;
@Immutable
@NotNullByDefault
public class MessageContext {
private final Metadata metadata;
private final Collection<MessageId> dependencies;
public MessageContext(@NotNull Metadata metadata,
@NotNull Collection<MessageId> dependencies) {
super(dependencies);
public MessageContext(Metadata metadata,
Collection<MessageId> dependencies) {
this.metadata = metadata;
this.dependencies = dependencies;
}
public MessageContext(@NotNull Metadata metadata) {
public MessageContext(Metadata metadata) {
this(metadata, Collections.<MessageId>emptyList());
}
@@ -25,4 +29,7 @@ public class MessageContext extends BaseMessageContext {
return metadata;
}
public Collection<MessageId> getDependencies() {
return dependencies;
}
}

View File

@@ -2,5 +2,7 @@ package org.briarproject.api.sync;
public interface MessageFactory {
Message createMessage(GroupId groupId, long timestamp, byte[] body);
Message createMessage(GroupId g, long timestamp, byte[] body);
Message createMessage(MessageId m, byte[] raw);
}