Use author encoding and parsing helpers everywhere.

This commit is contained in:
akwizgran
2018-01-16 17:38:21 +00:00
parent 68634e0f28
commit e474042af7
24 changed files with 190 additions and 290 deletions

View File

@@ -44,8 +44,8 @@ class RssFeedAdapter extends BriarAdapter<Feed, RssFeedAdapter.FeedViewHolder> {
ui.delete.setOnClickListener(v -> listener.onDeleteClick(item));
// Author
if (item.getAuthor() != null) {
ui.author.setText(item.getAuthor());
if (item.getRssAuthor() != null) {
ui.author.setText(item.getRssAuthor());
ui.author.setVisibility(VISIBLE);
ui.authorLabel.setVisibility(VISIBLE);
} else {

View File

@@ -24,10 +24,6 @@ public interface BlogConstants {
String KEY_TYPE = "type";
String KEY_TIMESTAMP = "timestamp";
String KEY_TIME_RECEIVED = "timeReceived";
String KEY_AUTHOR_ID = "id";
String KEY_FORMAT_VERSION = "formatVersion";
String KEY_AUTHOR_NAME = "name";
String KEY_PUBLIC_KEY = "publicKey";
String KEY_AUTHOR = "author";
String KEY_RSS_FEED = "rssFeed";
String KEY_READ = "read";

View File

@@ -16,26 +16,26 @@ public class Feed {
private final Blog blog;
private final LocalAuthor localAuthor;
@Nullable
private final String description, author;
private final String description, rssAuthor;
private final long added, updated, lastEntryTime;
public Feed(String url, Blog blog, LocalAuthor localAuthor,
@Nullable String description, @Nullable String author, long added,
long updated, long lastEntryTime) {
@Nullable String description, @Nullable String rssAuthor,
long added, long updated, long lastEntryTime) {
this.url = url;
this.blog = blog;
this.localAuthor = localAuthor;
this.description = description;
this.author = author;
this.rssAuthor = rssAuthor;
this.added = added;
this.updated = updated;
this.lastEntryTime = lastEntryTime;
}
public Feed(String url, Blog blog, LocalAuthor localAuthor,
@Nullable String description, @Nullable String author, long added) {
this(url, blog, localAuthor, description, author, added, 0L, 0L);
@Nullable String description, @Nullable String rssAuthor,
long added) {
this(url, blog, localAuthor, description, rssAuthor, added, 0L, 0L);
}
public Feed(String url, Blog blog, LocalAuthor localAuthor, long added) {
@@ -68,8 +68,8 @@ public class Feed {
}
@Nullable
public String getAuthor() {
return author;
public String getRssAuthor() {
return rssAuthor;
}
public long getAdded() {

View File

@@ -18,12 +18,10 @@ public interface FeedConstants {
// group metadata keys
String KEY_FEEDS = "feeds";
String KEY_FEED_URL = "feedURL";
String KEY_FORMAT_VERSION = "formatVersion";
String KEY_BLOG_TITLE = "blogTitle";
String KEY_PUBLIC_KEY = "publicKey";
String KEY_PRIVATE_KEY = "privateKey";
String KEY_FEED_DESC = "feedDesc";
String KEY_FEED_AUTHOR = "feedAuthor";
String KEY_FEED_PRIVATE_KEY = "feedPrivateKey";
String KEY_FEED_DESC = "feedDesc";
String KEY_FEED_RSS_AUTHOR = "feedRssAuthor";
String KEY_FEED_ADDED = "feedAdded";
String KEY_FEED_UPDATED = "feedUpdated";
String KEY_FEED_LAST_ENTRY = "feedLastEntryTime";

View File

@@ -23,10 +23,6 @@ public interface ForumConstants {
String KEY_TIMESTAMP = "timestamp";
String KEY_PARENT = "parent";
String KEY_AUTHOR = "author";
String KEY_ID = "id";
String KEY_FORMAT_VERSION = "formatVersion";
String KEY_NAME = "name";
String KEY_PUBLIC_KEY = "publicKey";
String KEY_LOCAL = "local";
String KEY_READ = "read";

View File

@@ -11,12 +11,12 @@ public interface PrivateGroupFactory {
/**
* Creates a private group with the given name and author.
*/
PrivateGroup createPrivateGroup(String name, Author author);
PrivateGroup createPrivateGroup(String name, Author creator);
/**
* Creates a private group with the given name, author and salt.
*/
PrivateGroup createPrivateGroup(String name, Author author, byte[] salt);
PrivateGroup createPrivateGroup(String name, Author creator, byte[] salt);
/**
* Parses a group and returns the corresponding PrivateGroup.

View File

@@ -4,7 +4,6 @@ import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorFactory;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.sync.Group;
import org.briarproject.bramble.api.sync.GroupFactory;
@@ -23,15 +22,12 @@ import static org.briarproject.briar.api.blog.BlogManager.CLIENT_VERSION;
class BlogFactoryImpl implements BlogFactory {
private final GroupFactory groupFactory;
private final AuthorFactory authorFactory;
private final ClientHelper clientHelper;
@Inject
BlogFactoryImpl(GroupFactory groupFactory, AuthorFactory authorFactory,
ClientHelper clientHelper) {
BlogFactoryImpl(GroupFactory groupFactory, ClientHelper clientHelper) {
this.groupFactory = groupFactory;
this.authorFactory = authorFactory;
this.clientHelper = clientHelper;
}
@@ -47,12 +43,7 @@ class BlogFactoryImpl implements BlogFactory {
private Blog createBlog(Author a, boolean rssFeed) {
try {
BdfList authorList = BdfList.of(
a.getFormatVersion(),
a.getName(),
a.getPublicKey()
);
BdfList blog = BdfList.of(authorList, rssFeed);
BdfList blog = BdfList.of(clientHelper.toList(a), rssFeed);
byte[] descriptor = clientHelper.toByteArray(blog);
Group g = groupFactory.createGroup(CLIENT_ID, CLIENT_VERSION,
descriptor);

View File

@@ -49,16 +49,11 @@ import javax.annotation.Nullable;
import javax.inject.Inject;
import static org.briarproject.bramble.api.contact.ContactManager.RemoveContactHook;
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_NAME;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_COMMENT;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_FORMAT_VERSION;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_MSG_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_PARENT_MSG_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PARENT_MSG_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PUBLIC_KEY;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_READ;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIMESTAMP;
@@ -68,7 +63,6 @@ import static org.briarproject.briar.api.blog.MessageType.COMMENT;
import static org.briarproject.briar.api.blog.MessageType.POST;
import static org.briarproject.briar.api.blog.MessageType.WRAPPED_COMMENT;
import static org.briarproject.briar.api.blog.MessageType.WRAPPED_POST;
import static org.briarproject.briar.blog.BlogPostValidator.authorToBdfDictionary;
@NotNullByDefault
class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
@@ -229,7 +223,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
BdfDictionary meta = new BdfDictionary();
meta.put(KEY_TYPE, POST.getInt());
meta.put(KEY_TIMESTAMP, p.getMessage().getTimestamp());
meta.put(KEY_AUTHOR, authorToBdfDictionary(p.getAuthor()));
meta.put(KEY_AUTHOR, clientHelper.toList(p.getAuthor()));
meta.put(KEY_READ, true);
meta.put(KEY_RSS_FEED, b.isRssFeed());
clientHelper.addLocalMessage(txn, p.getMessage(), meta, true);
@@ -272,7 +266,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
meta.put(KEY_ORIGINAL_MSG_ID, message.getId());
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, parentOriginalId);
meta.put(KEY_PARENT_MSG_ID, parentCurrentId);
meta.put(KEY_AUTHOR, authorToBdfDictionary(author));
meta.put(KEY_AUTHOR, clientHelper.toList(author));
// Send comment
clientHelper.addLocalMessage(txn, message, meta, true);
@@ -369,7 +363,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
"Unknown Message Type: " + type);
}
meta.put(KEY_ORIGINAL_MSG_ID, originalId);
meta.put(KEY_AUTHOR, authorToBdfDictionary(header.getAuthor()));
meta.put(KEY_AUTHOR, clientHelper.toList(header.getAuthor()));
meta.put(KEY_TIMESTAMP, header.getTimestamp());
meta.put(KEY_TIME_RECEIVED, header.getTimeReceived());
@@ -508,9 +502,9 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
// get all authors we need to get the status for
Set<AuthorId> authors = new HashSet<>();
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
authors.add(new AuthorId(
entry.getValue().getDictionary(KEY_AUTHOR)
.getRaw(KEY_AUTHOR_ID)));
BdfList authorList = entry.getValue().getList(KEY_AUTHOR);
Author a = clientHelper.parseAndValidateAuthor(authorList);
authors.add(a.getId());
}
// get statuses for all authors
Map<AuthorId, Status> authorStatuses = new HashMap<>();
@@ -575,21 +569,16 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
long timestamp = meta.getLong(KEY_TIMESTAMP);
long timeReceived = meta.getLong(KEY_TIME_RECEIVED, timestamp);
BdfDictionary authorDict = meta.getDictionary(KEY_AUTHOR);
AuthorId authorId = new AuthorId(authorDict.getRaw(KEY_AUTHOR_ID));
int formatVersion = authorDict.getLong(KEY_FORMAT_VERSION).intValue();
if (formatVersion != FORMAT_VERSION) throw new FormatException();
String name = authorDict.getString(KEY_AUTHOR_NAME);
byte[] publicKey = authorDict.getRaw(KEY_PUBLIC_KEY);
Author author = new Author(authorId, formatVersion, name, publicKey);
BdfList authorList = meta.getList(KEY_AUTHOR);
Author author = clientHelper.parseAndValidateAuthor(authorList);
boolean isFeedPost = meta.getBoolean(KEY_RSS_FEED, false);
Status authorStatus;
if (isFeedPost) {
authorStatus = Status.NONE;
} else if (authorStatuses.containsKey(authorId)) {
authorStatus = authorStatuses.get(authorId);
} else if (authorStatuses.containsKey(author.getId())) {
authorStatus = authorStatuses.get(author.getId());
} else {
authorStatus = identityManager.getAuthorStatus(txn, authorId);
authorStatus = identityManager.getAuthorStatus(txn, author.getId());
}
boolean read = meta.getBoolean(KEY_READ, false);

View File

@@ -3,7 +3,6 @@ package org.briarproject.briar.blog;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.contact.ContactManager;
import org.briarproject.bramble.api.data.MetadataEncoder;
import org.briarproject.bramble.api.identity.AuthorFactory;
import org.briarproject.bramble.api.lifecycle.LifecycleManager;
import org.briarproject.bramble.api.sync.GroupFactory;
import org.briarproject.bramble.api.sync.MessageFactory;
@@ -44,15 +43,14 @@ public class BlogModule {
}
@Provides
BlogPostFactory provideBlogPostFactory(ClientHelper clientHelper,
Clock clock) {
return new BlogPostFactoryImpl(clientHelper, clock);
BlogPostFactory provideBlogPostFactory(
BlogPostFactoryImpl blogPostFactory) {
return blogPostFactory;
}
@Provides
BlogFactory provideBlogFactory(GroupFactory groupFactory,
AuthorFactory authorFactory, ClientHelper clientHelper) {
return new BlogFactoryImpl(groupFactory, authorFactory, clientHelper);
BlogFactory provideBlogFactory(BlogFactoryImpl blogFactory) {
return blogFactory;
}
@Provides

View File

@@ -5,7 +5,6 @@ import org.briarproject.bramble.api.client.BdfMessageContext;
import org.briarproject.bramble.api.client.BdfMessageValidator;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.data.MetadataEncoder;
import org.briarproject.bramble.api.identity.Author;
@@ -31,14 +30,10 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATUR
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_NAME;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_COMMENT;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_FORMAT_VERSION;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_MSG_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_PARENT_MSG_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PARENT_MSG_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PUBLIC_KEY;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_READ;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIMESTAMP;
@@ -125,7 +120,7 @@ class BlogPostValidator extends BdfMessageValidator {
// Return the metadata and dependencies
BdfDictionary meta = new BdfDictionary();
meta.put(KEY_ORIGINAL_MSG_ID, m.getId());
meta.put(KEY_AUTHOR, authorToBdfDictionary(a));
meta.put(KEY_AUTHOR, clientHelper.toList(a));
meta.put(KEY_RSS_FEED, b.isRssFeed());
return new BdfMessageContext(meta);
}
@@ -174,7 +169,7 @@ class BlogPostValidator extends BdfMessageValidator {
meta.put(KEY_ORIGINAL_MSG_ID, m.getId());
meta.put(KEY_ORIGINAL_PARENT_MSG_ID, pOriginalId);
meta.put(KEY_PARENT_MSG_ID, currentId);
meta.put(KEY_AUTHOR, authorToBdfDictionary(a));
meta.put(KEY_AUTHOR, clientHelper.toList(a));
Collection<MessageId> dependencies = Collections.singleton(currentId);
return new BdfMessageContext(meta, dependencies);
}
@@ -214,7 +209,7 @@ class BlogPostValidator extends BdfMessageValidator {
BdfDictionary meta = new BdfDictionary();
meta.put(KEY_ORIGINAL_MSG_ID, wMessage.getId());
meta.put(KEY_TIMESTAMP, wTimestamp);
meta.put(KEY_AUTHOR, c.getDictionary().getDictionary(KEY_AUTHOR));
meta.put(KEY_AUTHOR, c.getDictionary().getList(KEY_AUTHOR));
meta.put(KEY_RSS_FEED, wBlog.isRssFeed());
return new BdfMessageContext(meta);
}
@@ -281,19 +276,10 @@ class BlogPostValidator extends BdfMessageValidator {
meta.put(KEY_PARENT_MSG_ID, parentId);
meta.put(KEY_TIMESTAMP, wTimestamp);
if (comment != null) meta.put(KEY_COMMENT, comment);
meta.put(KEY_AUTHOR, c.getDictionary().getDictionary(KEY_AUTHOR));
meta.put(KEY_AUTHOR, c.getDictionary().getList(KEY_AUTHOR));
return new BdfMessageContext(meta, dependencies);
}
static BdfDictionary authorToBdfDictionary(Author a) {
return BdfDictionary.of(
new BdfEntry(KEY_AUTHOR_ID, a.getId()),
new BdfEntry(KEY_FORMAT_VERSION, a.getFormatVersion()),
new BdfEntry(KEY_AUTHOR_NAME, a.getName()),
new BdfEntry(KEY_PUBLIC_KEY, a.getPublicKey())
);
}
private void addMessageMetadata(BdfMessageContext c, long time) {
c.getDictionary().put(KEY_TIMESTAMP, time);
c.getDictionary().put(KEY_TIME_RECEIVED, clock.currentTimeMillis());

View File

@@ -3,10 +3,13 @@ package org.briarproject.briar.feed;
import com.rometools.rome.feed.synd.SyndFeed;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.crypto.CryptoComponent;
import org.briarproject.bramble.api.crypto.KeyPair;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorFactory;
import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.system.Clock;
@@ -18,30 +21,31 @@ import org.briarproject.briar.api.feed.Feed;
import javax.inject.Inject;
import static org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_NAME_LENGTH;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_BLOG_TITLE;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_ADDED;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_AUTHOR;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_DESC;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_LAST_ENTRY;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_PRIVATE_KEY;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_RSS_AUTHOR;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_UPDATED;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FEED_URL;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_FORMAT_VERSION;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_PRIVATE_KEY;
import static org.briarproject.briar.api.feed.FeedConstants.KEY_PUBLIC_KEY;
class FeedFactoryImpl implements FeedFactory {
private final CryptoComponent cryptoComponent;
private final AuthorFactory authorFactory;
private final BlogFactory blogFactory;
private final ClientHelper clientHelper;
private final Clock clock;
@Inject
FeedFactoryImpl(CryptoComponent cryptoComponent,
AuthorFactory authorFactory, BlogFactory blogFactory, Clock clock) {
AuthorFactory authorFactory, BlogFactory blogFactory,
ClientHelper clientHelper, Clock clock) {
this.cryptoComponent = cryptoComponent;
this.authorFactory = authorFactory;
this.blogFactory = blogFactory;
this.clientHelper = clientHelper;
this.clock = clock;
}
@@ -73,41 +77,40 @@ class FeedFactoryImpl implements FeedFactory {
public Feed createFeed(BdfDictionary d) throws FormatException {
String url = d.getString(KEY_FEED_URL);
int formatVersion = d.getLong(KEY_FORMAT_VERSION).intValue();
String blogTitle = d.getString(KEY_BLOG_TITLE);
byte[] publicKey = d.getRaw(KEY_PUBLIC_KEY);
byte[] privateKey = d.getRaw(KEY_PRIVATE_KEY);
BdfList authorList = d.getList(KEY_FEED_AUTHOR);
byte[] privateKey = d.getRaw(KEY_FEED_PRIVATE_KEY);
Author author = clientHelper.parseAndValidateAuthor(authorList);
LocalAuthor localAuthor = authorFactory.createLocalAuthor(
formatVersion, blogTitle, publicKey, privateKey);
author.getFormatVersion(), author.getName(),
author.getPublicKey(), privateKey);
Blog blog = blogFactory.createFeedBlog(localAuthor);
String desc = d.getOptionalString(KEY_FEED_DESC);
String author = d.getOptionalString(KEY_FEED_AUTHOR);
String rssAuthor = d.getOptionalString(KEY_FEED_RSS_AUTHOR);
long added = d.getLong(KEY_FEED_ADDED, 0L);
long updated = d.getLong(KEY_FEED_UPDATED, 0L);
long lastEntryTime = d.getLong(KEY_FEED_LAST_ENTRY, 0L);
return new Feed(url, blog, localAuthor, desc, author, added,
return new Feed(url, blog, localAuthor, desc, rssAuthor, added,
updated, lastEntryTime);
}
@Override
public BdfDictionary feedToBdfDictionary(Feed feed) {
LocalAuthor localAuthor = feed.getLocalAuthor();
BdfList authorList = clientHelper.toList(localAuthor);
BdfDictionary d = BdfDictionary.of(
new BdfEntry(KEY_FEED_URL, feed.getUrl()),
new BdfEntry(KEY_FORMAT_VERSION,
localAuthor.getFormatVersion()),
new BdfEntry(KEY_BLOG_TITLE, localAuthor.getName()),
new BdfEntry(KEY_PUBLIC_KEY, localAuthor.getPublicKey()),
new BdfEntry(KEY_PRIVATE_KEY, localAuthor.getPrivateKey()),
new BdfEntry(KEY_FEED_AUTHOR, authorList),
new BdfEntry(KEY_FEED_PRIVATE_KEY, localAuthor.getPrivateKey()),
new BdfEntry(KEY_FEED_ADDED, feed.getAdded()),
new BdfEntry(KEY_FEED_UPDATED, feed.getUpdated()),
new BdfEntry(KEY_FEED_LAST_ENTRY, feed.getLastEntryTime())
);
if (feed.getDescription() != null)
d.put(KEY_FEED_DESC, feed.getDescription());
if (feed.getAuthor() != null) d.put(KEY_FEED_AUTHOR, feed.getAuthor());
if (feed.getRssAuthor() != null)
d.put(KEY_FEED_RSS_AUTHOR, feed.getRssAuthor());
return d;
}

View File

@@ -45,15 +45,10 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_FORMAT_VERSION;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_ID;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_LOCAL;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_NAME;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_PARENT;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_PUBLIC_KEY;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_TIMESTAMP;
import static org.briarproject.briar.client.MessageTrackerConstants.MSG_KEY_READ;
@@ -149,12 +144,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
meta.put(KEY_TIMESTAMP, p.getMessage().getTimestamp());
if (p.getParent() != null) meta.put(KEY_PARENT, p.getParent());
Author a = p.getAuthor();
BdfDictionary authorMeta = new BdfDictionary();
authorMeta.put(KEY_ID, a.getId());
authorMeta.put(KEY_FORMAT_VERSION, a.getFormatVersion());
authorMeta.put(KEY_NAME, a.getName());
authorMeta.put(KEY_PUBLIC_KEY, a.getPublicKey());
meta.put(KEY_AUTHOR, authorMeta);
meta.put(KEY_AUTHOR, clientHelper.toList(a));
meta.put(KEY_LOCAL, true);
meta.put(MSG_KEY_READ, true);
clientHelper.addLocalMessage(txn, p.getMessage(), meta, true);
@@ -240,10 +230,9 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
// get all authors we need to get the status for
Set<AuthorId> authors = new HashSet<>();
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
BdfDictionary d =
entry.getValue().getDictionary(KEY_AUTHOR, null);
if (d != null)
authors.add(new AuthorId(d.getRaw(KEY_ID)));
BdfList authorList = entry.getValue().getList(KEY_AUTHOR);
Author a = clientHelper.parseAndValidateAuthor(authorList);
authors.add(a.getId());
}
// get statuses for all authors
Map<AuthorId, Status> statuses = new HashMap<>();
@@ -301,14 +290,9 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
MessageId parentId = null;
if (meta.containsKey(KEY_PARENT))
parentId = new MessageId(meta.getRaw(KEY_PARENT));
BdfDictionary authorDict = meta.getDictionary(KEY_AUTHOR);
AuthorId authorId = new AuthorId(authorDict.getRaw(KEY_ID));
int formatVersion = authorDict.getLong(KEY_FORMAT_VERSION).intValue();
if (formatVersion != FORMAT_VERSION) throw new FormatException();
String name = authorDict.getString(KEY_NAME);
byte[] publicKey = authorDict.getRaw(KEY_PUBLIC_KEY);
Author author = new Author(authorId, formatVersion, name, publicKey);
Status status = statuses.get(authorId);
BdfList authorList = meta.getList(KEY_AUTHOR);
Author author = clientHelper.parseAndValidateAuthor(authorList);
Status status = statuses.get(author.getId());
if (status == null)
status = identityManager.getAuthorStatus(txn, author.getId());
boolean read = meta.getBoolean(MSG_KEY_READ);

View File

@@ -39,11 +39,7 @@ class ForumPostFactoryImpl implements ForumPostFactory {
if (StringUtils.utf8IsTooLong(body, MAX_FORUM_POST_BODY_LENGTH))
throw new IllegalArgumentException();
// Serialise the data to be signed
BdfList authorList = BdfList.of(
author.getFormatVersion(),
author.getName(),
author.getPublicKey()
);
BdfList authorList = clientHelper.toList(author);
BdfList signed = BdfList.of(groupId, timestamp, parent, authorList,
body);
// Sign the data

View File

@@ -26,11 +26,7 @@ import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_SIGNATUR
import static org.briarproject.bramble.util.ValidationUtils.checkLength;
import static org.briarproject.bramble.util.ValidationUtils.checkSize;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_FORMAT_VERSION;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_ID;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_NAME;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_PARENT;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_PUBLIC_KEY;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_READ;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_TIMESTAMP;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_BODY_LENGTH;
@@ -84,12 +80,7 @@ class ForumPostValidator extends BdfMessageValidator {
meta.put(KEY_PARENT, parent);
dependencies = Collections.singletonList(new MessageId(parent));
}
BdfDictionary authorMeta = new BdfDictionary();
authorMeta.put(KEY_ID, author.getId());
authorMeta.put(KEY_FORMAT_VERSION, author.getFormatVersion());
authorMeta.put(KEY_NAME, author.getName());
authorMeta.put(KEY_PUBLIC_KEY, author.getPublicKey());
meta.put(KEY_AUTHOR, authorMeta);
meta.put(KEY_AUTHOR, authorList);
meta.put(KEY_READ, false);
return new BdfMessageContext(meta, dependencies);
}

View File

@@ -10,10 +10,7 @@ interface GroupConstants {
String KEY_READ = MSG_KEY_READ;
String KEY_PARENT_MSG_ID = "parentMsgId";
String KEY_PREVIOUS_MSG_ID = "previousMsgId";
String KEY_MEMBER_ID = "memberId";
String KEY_MEMBER_FORMAT_VERSION = "formatVersion";
String KEY_MEMBER_NAME = "memberName";
String KEY_MEMBER_PUBLIC_KEY = "memberPublicKey";
String KEY_MEMBER = "member";
String KEY_INITIAL_JOIN_MSG = "initialJoinMsg";
String GROUP_KEY_MEMBERS = "members";

View File

@@ -50,11 +50,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
LocalAuthor member, @Nullable BdfList invite) {
try {
// Generate the signature
BdfList memberList = BdfList.of(
member.getFormatVersion(),
member.getName(),
member.getPublicKey()
);
BdfList memberList = clientHelper.toList(member);
BdfList toSign = BdfList.of(
groupId,
timestamp,
@@ -86,11 +82,7 @@ class GroupMessageFactoryImpl implements GroupMessageFactory {
MessageId previousMsgId) {
try {
// Generate the signature
BdfList memberList = BdfList.of(
member.getFormatVersion(),
member.getName(),
member.getPublicKey()
);
BdfList memberList = clientHelper.toList(member);
BdfList toSign = BdfList.of(
groupId,
timestamp,

View File

@@ -34,10 +34,7 @@ import static org.briarproject.briar.api.privategroup.MessageType.POST;
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_BODY_LENGTH;
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_INITIAL_JOIN_MSG;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_FORMAT_VERSION;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_ID;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_NAME;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_PUBLIC_KEY;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_PARENT_MSG_ID;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_PREVIOUS_MSG_ID;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_READ;
@@ -75,10 +72,10 @@ class GroupMessageValidator extends BdfMessageValidator {
BdfMessageContext c;
if (type == JOIN.getInt()) {
c = validateJoin(m, g, body, member);
addMessageMetadata(c, member, m.getTimestamp());
addMessageMetadata(c, memberList, m.getTimestamp());
} else if (type == POST.getInt()) {
c = validatePost(m, g, body, member);
addMessageMetadata(c, member, m.getTimestamp());
addMessageMetadata(c, memberList, m.getTimestamp());
} else {
throw new InvalidMessageException("Unknown Message Type");
}
@@ -187,15 +184,11 @@ class GroupMessageValidator extends BdfMessageValidator {
return new BdfMessageContext(meta, dependencies);
}
private void addMessageMetadata(BdfMessageContext c, Author member,
private void addMessageMetadata(BdfMessageContext c, BdfList member,
long timestamp) {
c.getDictionary().put(KEY_MEMBER, member);
c.getDictionary().put(KEY_TIMESTAMP, timestamp);
c.getDictionary().put(KEY_READ, false);
c.getDictionary().put(KEY_MEMBER_ID, member.getId());
c.getDictionary().put(KEY_MEMBER_FORMAT_VERSION,
member.getFormatVersion());
c.getDictionary().put(KEY_MEMBER_NAME, member.getName());
c.getDictionary().put(KEY_MEMBER_PUBLIC_KEY, member.getPublicKey());
}
}

View File

@@ -41,29 +41,25 @@ class PrivateGroupFactoryImpl implements PrivateGroupFactory {
}
@Override
public PrivateGroup createPrivateGroup(String name, Author author) {
public PrivateGroup createPrivateGroup(String name, Author creator) {
int length = StringUtils.toUtf8(name).length;
if (length == 0 || length > MAX_GROUP_NAME_LENGTH)
throw new IllegalArgumentException();
byte[] salt = new byte[GROUP_SALT_LENGTH];
random.nextBytes(salt);
return createPrivateGroup(name, author, salt);
return createPrivateGroup(name, creator, salt);
}
@Override
public PrivateGroup createPrivateGroup(String name, Author author,
public PrivateGroup createPrivateGroup(String name, Author creator,
byte[] salt) {
try {
BdfList creatorList = BdfList.of(
author.getFormatVersion(),
author.getName(),
author.getPublicKey()
);
BdfList creatorList = clientHelper.toList(creator);
BdfList group = BdfList.of(creatorList, name, salt);
byte[] descriptor = clientHelper.toByteArray(group);
Group g = groupFactory.createGroup(CLIENT_ID, CLIENT_VERSION,
descriptor);
return new PrivateGroup(g, name, author, salt);
return new PrivateGroup(g, name, creator, salt);
} catch (FormatException e) {
throw new RuntimeException(e);
}

View File

@@ -40,7 +40,6 @@ import org.briarproject.briar.api.privategroup.event.GroupMessageAddedEvent;
import org.briarproject.briar.client.BdfIncomingMessageHook;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -54,7 +53,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import javax.annotation.concurrent.ThreadSafe;
import javax.inject.Inject;
import static org.briarproject.bramble.api.identity.Author.FORMAT_VERSION;
import static org.briarproject.bramble.api.identity.Author.Status.OURSELVES;
import static org.briarproject.bramble.api.identity.Author.Status.UNVERIFIED;
import static org.briarproject.bramble.api.identity.Author.Status.VERIFIED;
@@ -70,10 +68,7 @@ import static org.briarproject.briar.privategroup.GroupConstants.GROUP_KEY_MEMBE
import static org.briarproject.briar.privategroup.GroupConstants.GROUP_KEY_OUR_GROUP;
import static org.briarproject.briar.privategroup.GroupConstants.GROUP_KEY_VISIBILITY;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_INITIAL_JOIN_MSG;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_FORMAT_VERSION;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_ID;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_NAME;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_PUBLIC_KEY;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_PARENT_MSG_ID;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_PREVIOUS_MSG_ID;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_READ;
@@ -242,12 +237,9 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
}
private void addMessageMetadata(BdfDictionary meta, GroupMessage m) {
meta.put(KEY_MEMBER, clientHelper.toList(m.getMember()));
meta.put(KEY_TIMESTAMP, m.getMessage().getTimestamp());
meta.put(KEY_READ, true);
meta.put(KEY_MEMBER_ID, m.getMember().getId());
meta.put(KEY_MEMBER_FORMAT_VERSION, m.getMember().getFormatVersion());
meta.put(KEY_MEMBER_NAME, m.getMember().getName());
meta.put(KEY_MEMBER_PUBLIC_KEY, m.getMember().getPublicKey());
}
@Override
@@ -334,8 +326,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
// get all authors we need to get the status for
Set<AuthorId> authors = new HashSet<>();
for (BdfDictionary meta : metadata.values()) {
byte[] idBytes = meta.getRaw(KEY_MEMBER_ID);
authors.add(new AuthorId(idBytes));
authors.add(getAuthor(meta).getId());
}
// get statuses for all authors
Map<AuthorId, Status> statuses = new HashMap<>();
@@ -350,13 +341,11 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
if (meta.getLong(KEY_TYPE) == JOIN.getInt()) {
Author member = getAuthor(meta);
Visibility v = visibilities.get(member);
headers.add(
getJoinMessageHeader(txn, g, entry.getKey(), meta,
statuses, v));
headers.add(getJoinMessageHeader(txn, g, entry.getKey(),
meta, statuses, v));
} else {
headers.add(
getGroupMessageHeader(txn, g, entry.getKey(), meta,
statuses));
headers.add(getGroupMessageHeader(txn, g, entry.getKey(),
meta, statuses));
}
}
db.commitTransaction(txn);
@@ -378,16 +367,16 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
}
long timestamp = meta.getLong(KEY_TIMESTAMP);
Author author = getAuthor(meta);
Author member = getAuthor(meta);
Status status;
if (statuses.containsKey(author.getId())) {
status = statuses.get(author.getId());
if (statuses.containsKey(member.getId())) {
status = statuses.get(member.getId());
} else {
status = identityManager.getAuthorStatus(txn, author.getId());
status = identityManager.getAuthorStatus(txn, member.getId());
}
boolean read = meta.getBoolean(KEY_READ);
return new GroupMessageHeader(g, id, parentId, timestamp, author,
return new GroupMessageHeader(g, id, parentId, timestamp, member,
status, read);
}
@@ -477,8 +466,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
boolean foundMember = false, changed = false;
for (int i = 0; i < members.size(); i++) {
BdfDictionary d = members.getDictionary(i);
AuthorId memberId = new AuthorId(d.getRaw(KEY_MEMBER_ID));
if (a.equals(memberId)) {
if (a.equals(getAuthor(d).getId())) {
foundMember = true;
// Don't update the visibility if the contact is already visible
if (getVisibility(d) == INVISIBLE) {
@@ -567,8 +555,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
if (timestamp <= previousMeta.getLong(KEY_TIMESTAMP))
throw new FormatException();
// previous message must be from same member
if (!Arrays.equals(meta.getRaw(KEY_MEMBER_ID),
previousMeta.getRaw(KEY_MEMBER_ID)))
if (!getAuthor(meta).equals(getAuthor(previousMeta)))
throw new FormatException();
// previous message must be a POST or JOIN
MessageType previousType = MessageType
@@ -605,10 +592,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
BdfDictionary meta = clientHelper.getGroupMetadataAsDictionary(txn, g);
BdfList members = meta.getList(GROUP_KEY_MEMBERS);
members.add(BdfDictionary.of(
new BdfEntry(KEY_MEMBER_ID, a.getId()),
new BdfEntry(KEY_MEMBER_FORMAT_VERSION, a.getFormatVersion()),
new BdfEntry(KEY_MEMBER_NAME, a.getName()),
new BdfEntry(KEY_MEMBER_PUBLIC_KEY, a.getPublicKey()),
new BdfEntry(KEY_MEMBER, clientHelper.toList(a)),
new BdfEntry(GROUP_KEY_VISIBILITY, v.getInt())
));
clientHelper.mergeGroupMetadata(txn, g, meta);
@@ -618,12 +602,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
}
private Author getAuthor(BdfDictionary meta) throws FormatException {
AuthorId authorId = new AuthorId(meta.getRaw(KEY_MEMBER_ID));
int formatVersion = meta.getLong(KEY_MEMBER_FORMAT_VERSION).intValue();
if (formatVersion != FORMAT_VERSION) throw new FormatException();
String name = meta.getString(KEY_MEMBER_NAME);
byte[] publicKey = meta.getRaw(KEY_MEMBER_PUBLIC_KEY);
return new Author(authorId, formatVersion, name, publicKey);
return clientHelper.parseAndValidateAuthor(meta.getList(KEY_MEMBER));
}
private Visibility getVisibility(BdfDictionary meta)

View File

@@ -78,11 +78,7 @@ class MessageEncoderImpl implements MessageEncoder {
GroupId privateGroupId, long timestamp, String groupName,
Author creator, byte[] salt, @Nullable String message,
byte[] signature) {
BdfList creatorList = BdfList.of(
creator.getFormatVersion(),
creator.getName(),
creator.getPublicKey()
);
BdfList creatorList = clientHelper.toList(creator);
BdfList body = BdfList.of(
INVITE.getValue(),
creatorList,

View File

@@ -39,14 +39,10 @@ import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_NAME;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_COMMENT;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_FORMAT_VERSION;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_MSG_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_PARENT_MSG_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PARENT_MSG_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PUBLIC_KEY;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_READ;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_TIMESTAMP;
@@ -76,7 +72,7 @@ public class BlogManagerImplTest extends BriarTestCase {
context.mock(BlogPostFactory.class);
private final LocalAuthor localAuthor1, localAuthor2, rssLocalAuthor;
private final BdfDictionary authorDict1, authorDict2, rssAuthorDict;
private final BdfList authorList1, authorList2, rssAuthorList;
private final Blog blog1, blog2, rssBlog;
private final long timestamp, timeReceived;
private final MessageId messageId, rssMessageId;
@@ -91,9 +87,9 @@ public class BlogManagerImplTest extends BriarTestCase {
localAuthor1 = getLocalAuthor();
localAuthor2 = getLocalAuthor();
rssLocalAuthor = getLocalAuthor();
authorDict1 = authorToBdfDictionary(localAuthor1);
authorDict2 = authorToBdfDictionary(localAuthor2);
rssAuthorDict = authorToBdfDictionary(rssLocalAuthor);
authorList1 = authorToBdfList(localAuthor1);
authorList2 = authorToBdfList(localAuthor2);
rssAuthorList = authorToBdfList(rssLocalAuthor);
blog1 = createBlog(localAuthor1, false);
blog2 = createBlog(localAuthor2, false);
rssBlog = createBlog(rssLocalAuthor, true);
@@ -173,12 +169,14 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TYPE, POST.getInt()),
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived),
new BdfEntry(KEY_AUTHOR, authorDict1),
new BdfEntry(KEY_AUTHOR, authorList1),
new BdfEntry(KEY_READ, false),
new BdfEntry(KEY_RSS_FEED, false)
);
context.checking(new Expectations() {{
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
will(returnValue(VERIFIED));
}});
@@ -212,11 +210,16 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TYPE, POST.getInt()),
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived),
new BdfEntry(KEY_AUTHOR, rssAuthorDict),
new BdfEntry(KEY_AUTHOR, rssAuthorList),
new BdfEntry(KEY_READ, false),
new BdfEntry(KEY_RSS_FEED, true)
);
context.checking(new Expectations() {{
oneOf(clientHelper).parseAndValidateAuthor(rssAuthorList);
will(returnValue(rssLocalAuthor));
}});
blogManager.incomingMessage(txn, rssMessage, body, meta);
context.assertIsSatisfied();
@@ -263,7 +266,7 @@ public class BlogManagerImplTest extends BriarTestCase {
BdfDictionary meta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, POST.getInt()),
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_AUTHOR, authorDict1),
new BdfEntry(KEY_AUTHOR, authorList1),
new BdfEntry(KEY_READ, true),
new BdfEntry(KEY_RSS_FEED, false)
);
@@ -275,7 +278,11 @@ public class BlogManagerImplTest extends BriarTestCase {
will(returnValue(blog1.getGroup()));
oneOf(blogFactory).parseBlog(blog1.getGroup());
will(returnValue(blog1));
oneOf(clientHelper).toList(localAuthor1);
will(returnValue(authorList1));
oneOf(clientHelper).addLocalMessage(txn, message, meta, true);
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
will(returnValue(OURSELVES));
oneOf(db).commitTransaction(txn);
@@ -309,7 +316,7 @@ public class BlogManagerImplTest extends BriarTestCase {
BdfDictionary meta = BdfDictionary.of(
new BdfEntry(KEY_TYPE, POST.getInt()),
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_AUTHOR, rssAuthorDict),
new BdfEntry(KEY_AUTHOR, rssAuthorList),
new BdfEntry(KEY_READ, true),
new BdfEntry(KEY_RSS_FEED, true)
);
@@ -321,7 +328,11 @@ public class BlogManagerImplTest extends BriarTestCase {
will(returnValue(rssBlog.getGroup()));
oneOf(blogFactory).parseBlog(rssBlog.getGroup());
will(returnValue(rssBlog));
oneOf(clientHelper).toList(rssLocalAuthor);
will(returnValue(rssAuthorList));
oneOf(clientHelper).addLocalMessage(txn, rssMessage, meta, true);
oneOf(clientHelper).parseAndValidateAuthor(rssAuthorList);
will(returnValue(rssLocalAuthor));
oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn);
}});
@@ -356,7 +367,7 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TYPE, POST.getInt()),
new BdfEntry(KEY_RSS_FEED, false),
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
new BdfEntry(KEY_AUTHOR, authorDict1),
new BdfEntry(KEY_AUTHOR, authorList1),
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
);
@@ -370,7 +381,7 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_ORIGINAL_MSG_ID, commentId),
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, messageId),
new BdfEntry(KEY_PARENT_MSG_ID, messageId),
new BdfEntry(KEY_AUTHOR, authorDict1)
new BdfEntry(KEY_AUTHOR, authorList1)
);
context.checking(new Expectations() {{
@@ -380,14 +391,20 @@ public class BlogManagerImplTest extends BriarTestCase {
oneOf(blogPostFactory).createBlogComment(blog1.getId(),
localAuthor1, comment, messageId, messageId);
will(returnValue(commentMsg));
oneOf(clientHelper).toList(localAuthor1);
will(returnValue(authorList1));
// Store the comment
oneOf(clientHelper).addLocalMessage(txn, commentMsg, commentMeta,
true);
// Create the headers for the comment and its parent
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
will(returnValue(OURSELVES));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn, messageId);
will(returnValue(postMeta));
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
will(returnValue(OURSELVES));
oneOf(db).commitTransaction(txn);
@@ -446,7 +463,7 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
new BdfEntry(KEY_RSS_FEED, false),
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
new BdfEntry(KEY_AUTHOR, authorDict1),
new BdfEntry(KEY_AUTHOR, authorList1),
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
);
@@ -460,7 +477,7 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_ORIGINAL_MSG_ID, commentId),
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, messageId),
new BdfEntry(KEY_PARENT_MSG_ID, wrappedPostId),
new BdfEntry(KEY_AUTHOR, authorDict2)
new BdfEntry(KEY_AUTHOR, authorList2)
);
context.checking(new Expectations() {{
@@ -475,6 +492,8 @@ public class BlogManagerImplTest extends BriarTestCase {
blog1.getGroup().getDescriptor(), timestamp,
originalPostBody);
will(returnValue(wrappedPostMsg));
oneOf(clientHelper).toList(localAuthor1);
will(returnValue(authorList1));
// Store the wrapped post
oneOf(clientHelper).addLocalMessage(txn, wrappedPostMsg,
wrappedPostMeta, true);
@@ -482,15 +501,21 @@ public class BlogManagerImplTest extends BriarTestCase {
oneOf(blogPostFactory).createBlogComment(blog2.getId(),
localAuthor2, comment, messageId, wrappedPostId);
will(returnValue(commentMsg));
oneOf(clientHelper).toList(localAuthor2);
will(returnValue(authorList2));
// Store the comment
oneOf(clientHelper).addLocalMessage(txn, commentMsg, commentMeta,
true);
// Create the headers for the comment and the wrapped post
oneOf(clientHelper).parseAndValidateAuthor(authorList2);
will(returnValue(localAuthor2));
oneOf(identityManager).getAuthorStatus(txn, localAuthor2.getId());
will(returnValue(OURSELVES));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
wrappedPostId);
will(returnValue(wrappedPostMeta));
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
will(returnValue(VERIFIED));
oneOf(db).commitTransaction(txn);
@@ -549,7 +574,7 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
new BdfEntry(KEY_RSS_FEED, true),
new BdfEntry(KEY_ORIGINAL_MSG_ID, rssMessageId),
new BdfEntry(KEY_AUTHOR, rssAuthorDict),
new BdfEntry(KEY_AUTHOR, rssAuthorList),
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
);
@@ -563,7 +588,7 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_ORIGINAL_MSG_ID, commentId),
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, rssMessageId),
new BdfEntry(KEY_PARENT_MSG_ID, wrappedPostId),
new BdfEntry(KEY_AUTHOR, authorDict1)
new BdfEntry(KEY_AUTHOR, authorList1)
);
context.checking(new Expectations() {{
@@ -578,6 +603,8 @@ public class BlogManagerImplTest extends BriarTestCase {
rssBlog.getGroup().getDescriptor(), timestamp,
originalPostBody);
will(returnValue(wrappedPostMsg));
oneOf(clientHelper).toList(rssLocalAuthor);
will(returnValue(rssAuthorList));
// Store the wrapped post
oneOf(clientHelper).addLocalMessage(txn, wrappedPostMsg,
wrappedPostMeta, true);
@@ -585,15 +612,21 @@ public class BlogManagerImplTest extends BriarTestCase {
oneOf(blogPostFactory).createBlogComment(blog1.getId(),
localAuthor1, comment, rssMessageId, wrappedPostId);
will(returnValue(commentMsg));
oneOf(clientHelper).toList(localAuthor1);
will(returnValue(authorList1));
// Store the comment
oneOf(clientHelper).addLocalMessage(txn, commentMsg, commentMeta,
true);
// Create the headers for the comment and the wrapped post
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
will(returnValue(OURSELVES));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
wrappedPostId);
will(returnValue(wrappedPostMeta));
oneOf(clientHelper).parseAndValidateAuthor(rssAuthorList);
will(returnValue(rssLocalAuthor));
oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn);
}});
@@ -654,7 +687,7 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_TYPE, WRAPPED_POST.getInt()),
new BdfEntry(KEY_RSS_FEED, true),
new BdfEntry(KEY_ORIGINAL_MSG_ID, messageId),
new BdfEntry(KEY_AUTHOR, rssAuthorDict),
new BdfEntry(KEY_AUTHOR, rssAuthorList),
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
);
@@ -666,7 +699,7 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_COMMENT, comment),
new BdfEntry(KEY_PARENT_MSG_ID, rewrappedPostId),
new BdfEntry(KEY_ORIGINAL_MSG_ID, originalCommentId),
new BdfEntry(KEY_AUTHOR, authorDict1),
new BdfEntry(KEY_AUTHOR, authorList1),
new BdfEntry(KEY_TIMESTAMP, timestamp),
new BdfEntry(KEY_TIME_RECEIVED, timeReceived)
);
@@ -681,7 +714,7 @@ public class BlogManagerImplTest extends BriarTestCase {
new BdfEntry(KEY_ORIGINAL_MSG_ID, localCommentId),
new BdfEntry(KEY_ORIGINAL_PARENT_MSG_ID, originalCommentId),
new BdfEntry(KEY_PARENT_MSG_ID, wrappedCommentId),
new BdfEntry(KEY_AUTHOR, authorDict2)
new BdfEntry(KEY_AUTHOR, authorList2)
);
context.checking(new Expectations() {{
@@ -693,6 +726,8 @@ public class BlogManagerImplTest extends BriarTestCase {
oneOf(blogPostFactory).rewrapWrappedPost(blog2.getId(),
wrappedPostBody);
will(returnValue(rewrappedPostMsg));
oneOf(clientHelper).toList(rssLocalAuthor);
will(returnValue(rssAuthorList));
// Store the rewrapped post
oneOf(clientHelper).addLocalMessage(txn, rewrappedPostMsg,
rewrappedPostMeta, true);
@@ -708,6 +743,8 @@ public class BlogManagerImplTest extends BriarTestCase {
blog1.getGroup().getDescriptor(), timestamp,
originalCommentBody, rewrappedPostId);
will(returnValue(wrappedCommentMsg));
oneOf(clientHelper).toList(localAuthor1);
will(returnValue(authorList1));
// Store the wrapped comment
oneOf(clientHelper).addLocalMessage(txn, wrappedCommentMsg,
wrappedCommentMeta, true);
@@ -716,21 +753,29 @@ public class BlogManagerImplTest extends BriarTestCase {
localAuthor2, localComment, originalCommentId,
wrappedCommentId);
will(returnValue(localCommentMsg));
oneOf(clientHelper).toList(localAuthor2);
will(returnValue(authorList2));
// Store the new comment
oneOf(clientHelper).addLocalMessage(txn, localCommentMsg,
localCommentMeta, true);
// Create the headers for the new comment, the wrapped comment and
// the rewrapped post
oneOf(clientHelper).parseAndValidateAuthor(authorList2);
will(returnValue(localAuthor2));
oneOf(identityManager).getAuthorStatus(txn, localAuthor2.getId());
will(returnValue(OURSELVES));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
wrappedCommentId);
will(returnValue(wrappedCommentMeta));
oneOf(clientHelper).parseAndValidateAuthor(authorList1);
will(returnValue(localAuthor1));
oneOf(identityManager).getAuthorStatus(txn, localAuthor1.getId());
will(returnValue(VERIFIED));
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
rewrappedPostId);
will(returnValue(rewrappedPostMeta));
oneOf(clientHelper).parseAndValidateAuthor(rssAuthorList);
will(returnValue(rssLocalAuthor));
oneOf(db).commitTransaction(txn);
oneOf(db).endTransaction(txn);
}});
@@ -827,13 +872,8 @@ public class BlogManagerImplTest extends BriarTestCase {
return new Blog(group, localAuthor, rssFeed);
}
private BdfDictionary authorToBdfDictionary(Author a) {
return BdfDictionary.of(
new BdfEntry(KEY_AUTHOR_ID, a.getId()),
new BdfEntry(KEY_FORMAT_VERSION, a.getFormatVersion()),
new BdfEntry(KEY_AUTHOR_NAME, a.getName()),
new BdfEntry(KEY_PUBLIC_KEY, a.getPublicKey())
);
private BdfList authorToBdfList(Author a) {
return BdfList.of(a.getFormatVersion(), a.getName(), a.getPublicKey());
}
}

View File

@@ -3,7 +3,6 @@ package org.briarproject.briar.blog;
import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.client.ClientHelper;
import org.briarproject.bramble.api.data.BdfDictionary;
import org.briarproject.bramble.api.data.BdfEntry;
import org.briarproject.bramble.api.data.BdfList;
import org.briarproject.bramble.api.data.MetadataEncoder;
import org.briarproject.bramble.api.identity.Author;
@@ -30,14 +29,10 @@ import static org.briarproject.bramble.test.TestUtils.getRandomBytes;
import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_AUTHOR_NAME;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_COMMENT;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_FORMAT_VERSION;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_MSG_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_ORIGINAL_PARENT_MSG_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PARENT_MSG_ID;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_PUBLIC_KEY;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_READ;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_RSS_FEED;
import static org.briarproject.briar.api.blog.BlogManager.CLIENT_ID;
@@ -55,7 +50,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
private final Mockery context = new Mockery();
private final Blog blog, rssBlog;
private final BdfDictionary authorDict;
private final BdfList authorList;
private final byte[] descriptor;
private final Group group;
private final Message message;
@@ -73,11 +68,10 @@ public class BlogPostValidatorTest extends BriarTestCase {
descriptor = getRandomBytes(42);
group = new Group(groupId, CLIENT_ID, descriptor);
author = getAuthor();
authorDict = BdfDictionary.of(
new BdfEntry(KEY_AUTHOR_ID, author.getId()),
new BdfEntry(KEY_FORMAT_VERSION, author.getFormatVersion()),
new BdfEntry(KEY_AUTHOR_NAME, author.getName()),
new BdfEntry(KEY_PUBLIC_KEY, author.getPublicKey())
authorList = BdfList.of(
author.getFormatVersion(),
author.getName(),
author.getPublicKey()
);
blog = new Blog(group, author, false);
rssBlog = new Blog(group, author, true);
@@ -117,7 +111,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
BdfDictionary result =
validator.validateMessage(message, group, m).getDictionary();
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
assertEquals(authorList, result.getList(KEY_AUTHOR));
assertFalse(result.getBoolean(KEY_READ));
assertEquals(rssFeed, result.getBoolean(KEY_RSS_FEED));
context.assertIsSatisfied();
@@ -129,7 +123,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
BdfList content = BdfList.of(null, null, body);
BdfList m = BdfList.of(POST.getInt(), content, null);
validator.validateMessage(message, group, m).getDictionary();
validator.validateMessage(message, group, m);
}
@Test(expected = FormatException.class)
@@ -138,7 +132,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
BdfList content = BdfList.of(null, null, body, null);
BdfList m = BdfList.of(POST.getInt(), content, null);
validator.validateMessage(message, group, m).getDictionary();
validator.validateMessage(message, group, m);
}
@Test
@@ -159,7 +153,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
validator.validateMessage(message, group, m).getDictionary();
assertEquals(comment, result.getString(KEY_COMMENT));
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
assertEquals(authorList, result.getList(KEY_AUTHOR));
assertEquals(pOriginalId.getBytes(),
result.getRaw(KEY_ORIGINAL_PARENT_MSG_ID));
assertEquals(currentId.getBytes(), result.getRaw(KEY_PARENT_MSG_ID));
@@ -229,7 +223,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
BdfDictionary result =
validator.validateMessage(message, group, m).getDictionary();
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
assertEquals(authorList, result.getList(KEY_AUTHOR));
assertEquals(rssFeed, result.getBoolean(KEY_RSS_FEED));
context.assertIsSatisfied();
}
@@ -272,7 +266,7 @@ public class BlogPostValidatorTest extends BriarTestCase {
validator.validateMessage(message, group, m).getDictionary();
assertEquals(comment, result.getString(KEY_COMMENT));
assertEquals(authorDict, result.getDictionary(KEY_AUTHOR));
assertEquals(authorList, result.getList(KEY_AUTHOR));
assertEquals(
message.getId().getBytes(), result.getRaw(KEY_ORIGINAL_MSG_ID));
assertEquals(currentId.getBytes(), result.getRaw(KEY_PARENT_MSG_ID));
@@ -284,6 +278,8 @@ public class BlogPostValidatorTest extends BriarTestCase {
context.checking(new Expectations() {{
oneOf(blogFactory).parseBlog(group);
will(returnValue(b));
oneOf(clientHelper).toList(b.getAuthor());
will(returnValue(authorList));
oneOf(clientHelper)
.verifySignature(label, sig, author.getPublicKey(), signed);
}});

View File

@@ -22,11 +22,7 @@ import static org.briarproject.bramble.test.TestUtils.getRandomId;
import static org.briarproject.bramble.util.StringUtils.getRandomString;
import static org.briarproject.briar.api.blog.BlogConstants.KEY_READ;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_AUTHOR;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_FORMAT_VERSION;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_ID;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_NAME;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_PARENT;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_PUBLIC_KEY;
import static org.briarproject.briar.api.forum.ForumConstants.KEY_TIMESTAMP;
import static org.briarproject.briar.api.forum.ForumConstants.MAX_FORUM_POST_BODY_LENGTH;
import static org.briarproject.briar.api.forum.ForumPostFactory.SIGNING_LABEL_POST;
@@ -74,7 +70,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
BdfMessageContext messageContext = v.validateMessage(message, group,
BdfList.of(null, authorList, content, signature));
assertExpectedContext(messageContext, false, authorName);
assertExpectedContext(messageContext, false);
}
@Test(expected = FormatException.class)
@@ -149,7 +145,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
BdfMessageContext messageContext = v.validateMessage(message, group,
BdfList.of(parentId, authorList, shortContent, signature));
assertExpectedContext(messageContext, true, authorName);
assertExpectedContext(messageContext, true);
}
@Test(expected = FormatException.class)
@@ -224,7 +220,7 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
}
private void assertExpectedContext(BdfMessageContext messageContext,
boolean hasParent, String authorName) throws FormatException {
boolean hasParent) throws FormatException {
BdfDictionary meta = messageContext.getDictionary();
Collection<MessageId> dependencies = messageContext.getDependencies();
if (hasParent) {
@@ -238,12 +234,6 @@ public class ForumPostValidatorTest extends ValidatorTestCase {
}
assertEquals(timestamp, meta.getLong(KEY_TIMESTAMP).longValue());
assertFalse(meta.getBoolean(KEY_READ));
BdfDictionary authorMeta = meta.getDictionary(KEY_AUTHOR);
assertEquals(4, authorMeta.size());
assertArrayEquals(author.getId().getBytes(), authorMeta.getRaw(KEY_ID));
assertEquals(author.getFormatVersion(),
authorMeta.getLong(KEY_FORMAT_VERSION).intValue());
assertEquals(authorName, authorMeta.getString(KEY_NAME));
assertArrayEquals(authorPublicKey, authorMeta.getRaw(KEY_PUBLIC_KEY));
assertEquals(authorList, meta.getList(KEY_AUTHOR));
}
}

View File

@@ -34,10 +34,7 @@ import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_
import static org.briarproject.briar.api.privategroup.PrivateGroupConstants.MAX_GROUP_POST_BODY_LENGTH;
import static org.briarproject.briar.api.privategroup.invitation.GroupInvitationFactory.SIGNING_LABEL_INVITE;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_INITIAL_JOIN_MSG;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_FORMAT_VERSION;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_ID;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_NAME;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER_PUBLIC_KEY;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_MEMBER;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_PARENT_MSG_ID;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_PREVIOUS_MSG_ID;
import static org.briarproject.briar.privategroup.GroupConstants.KEY_READ;
@@ -180,7 +177,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
memberSignature);
BdfMessageContext messageContext =
validator.validateMessage(message, group, body);
assertExpectedMessageContext(messageContext, JOIN, creator,
assertExpectedMessageContext(messageContext, JOIN, creatorList,
Collections.emptyList());
assertTrue(messageContext.getDictionary()
.getBoolean(KEY_INITIAL_JOIN_MSG));
@@ -365,7 +362,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
memberSignature);
BdfMessageContext messageContext =
validator.validateMessage(message, group, body);
assertExpectedMessageContext(messageContext, JOIN, member,
assertExpectedMessageContext(messageContext, JOIN, memberList,
Collections.emptyList());
assertFalse(messageContext.getDictionary()
.getBoolean(KEY_INITIAL_JOIN_MSG));
@@ -616,7 +613,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
expectPostMessage(parentId, true);
BdfMessageContext messageContext =
validator.validateMessage(message, group, body);
assertExpectedMessageContext(messageContext, POST, member,
assertExpectedMessageContext(messageContext, POST, memberList,
Arrays.asList(parentId, previousMsgId));
assertArrayEquals(previousMsgId.getBytes(),
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
@@ -631,7 +628,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
expectPostMessage(null, true);
BdfMessageContext messageContext =
validator.validateMessage(message, group, body);
assertExpectedMessageContext(messageContext, POST, member,
assertExpectedMessageContext(messageContext, POST, memberList,
Collections.singletonList(previousMsgId));
assertArrayEquals(previousMsgId.getBytes(),
messageContext.getDictionary().getRaw(KEY_PREVIOUS_MSG_ID));
@@ -659,18 +656,14 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
}
private void assertExpectedMessageContext(BdfMessageContext c,
MessageType type, Author member,
MessageType type, BdfList member,
Collection<MessageId> dependencies) throws FormatException {
BdfDictionary d = c.getDictionary();
assertEquals(type.getInt(), d.getLong(KEY_TYPE).intValue());
assertEquals(message.getTimestamp(),
d.getLong(KEY_TIMESTAMP).longValue());
assertFalse(d.getBoolean(KEY_READ));
assertEquals(member.getId().getBytes(), d.getRaw(KEY_MEMBER_ID));
assertEquals(member.getFormatVersion(),
d.getLong(KEY_MEMBER_FORMAT_VERSION).intValue());
assertEquals(member.getName(), d.getString(KEY_MEMBER_NAME));
assertEquals(member.getPublicKey(), d.getRaw(KEY_MEMBER_PUBLIC_KEY));
assertEquals(member, d.getList(KEY_MEMBER));
assertEquals(dependencies, c.getDependencies());
}