Verified Commit e474042a authored by akwizgran's avatar akwizgran

Use author encoding and parsing helpers everywhere.

parent 68634e0f
......@@ -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 {
......
......@@ -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";
......
......@@ -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() {
......
......@@ -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";
......
......@@ -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";
......
......@@ -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.
......
......@@ -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);
......
......@@ -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);
......
......@@ -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
......
......@@ -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());
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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
......
......@@ -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);
}
......
......@@ -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";
......
......@@ -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,
......
......@@ -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 {