@Test(expected = FormatException.class) public void testRejectsNullContent() throws Exception { expectCreateAuthor(); v.validateMessage(message, group, BdfList.of(parentId, authorList, null, signature)); }
@Override protected BdfMessageContext validateMessage(Message m, Group g, BdfList body) throws InvalidMessageException, FormatException { checkSize(body, 4); byte[] parent = body.getOptionalRaw(0); checkLength(parent, UniqueId.LENGTH); BdfList authorList = body.getList(1); Author author = clientHelper.parseAndValidateAuthor(authorList); String content = body.getString(2); checkLength(content, 0, MAX_FORUM_POST_BODY_LENGTH); byte[] sig = body.getRaw(3); checkLength(sig, 1, MAX_SIGNATURE_LENGTH); BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), parent, authorList, content); try { clientHelper.verifySignature(sig, SIGNING_LABEL_POST, signed, author.getPublicKey()); } catch (GeneralSecurityException e) { throw new InvalidMessageException(e); } BdfDictionary meta = new BdfDictionary(); Collection<MessageId> dependencies = Collections.emptyList(); meta.put(KEY_TIMESTAMP, m.getTimestamp()); if (parent != null) { meta.put(KEY_PARENT, parent); dependencies = Collections.singletonList(new MessageId(parent)); } meta.put(KEY_AUTHOR, authorList); meta.put(KEY_READ, false); return new BdfMessageContext(meta, dependencies); }
ForumPostValidator extends BdfMessageValidator { @Override protected BdfMessageContext validateMessage(Message m, Group g, BdfList body) throws InvalidMessageException, FormatException { checkSize(body, 4); byte[] parent = body.getOptionalRaw(0); checkLength(parent, UniqueId.LENGTH); BdfList authorList = body.getList(1); Author author = clientHelper.parseAndValidateAuthor(authorList); String content = body.getString(2); checkLength(content, 0, MAX_FORUM_POST_BODY_LENGTH); byte[] sig = body.getRaw(3); checkLength(sig, 1, MAX_SIGNATURE_LENGTH); BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), parent, authorList, content); try { clientHelper.verifySignature(sig, SIGNING_LABEL_POST, signed, author.getPublicKey()); } catch (GeneralSecurityException e) { throw new InvalidMessageException(e); } BdfDictionary meta = new BdfDictionary(); Collection<MessageId> dependencies = Collections.emptyList(); meta.put(KEY_TIMESTAMP, m.getTimestamp()); if (parent != null) { meta.put(KEY_PARENT, parent); dependencies = Collections.singletonList(new MessageId(parent)); } meta.put(KEY_AUTHOR, authorList); meta.put(KEY_READ, false); return new BdfMessageContext(meta, dependencies); } }
ForumPostValidator extends BdfMessageValidator { @Override protected BdfMessageContext validateMessage(Message m, Group g, BdfList body) throws InvalidMessageException, FormatException { checkSize(body, 4); byte[] parent = body.getOptionalRaw(0); checkLength(parent, UniqueId.LENGTH); BdfList authorList = body.getList(1); Author author = clientHelper.parseAndValidateAuthor(authorList); String content = body.getString(2); checkLength(content, 0, MAX_FORUM_POST_BODY_LENGTH); byte[] sig = body.getRaw(3); checkLength(sig, 1, MAX_SIGNATURE_LENGTH); BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), parent, authorList, content); try { clientHelper.verifySignature(sig, SIGNING_LABEL_POST, signed, author.getPublicKey()); } catch (GeneralSecurityException e) { throw new InvalidMessageException(e); } BdfDictionary meta = new BdfDictionary(); Collection<MessageId> dependencies = Collections.emptyList(); meta.put(KEY_TIMESTAMP, m.getTimestamp()); if (parent != null) { meta.put(KEY_PARENT, parent); dependencies = Collections.singletonList(new MessageId(parent)); } meta.put(KEY_AUTHOR, authorList); meta.put(KEY_READ, false); return new BdfMessageContext(meta, dependencies); } ForumPostValidator(ClientHelper clientHelper,
			MetadataEncoder metadataEncoder, Clock clock); }
ForumPostValidator extends BdfMessageValidator { @Override protected BdfMessageContext validateMessage(Message m, Group g, BdfList body) throws InvalidMessageException, FormatException { checkSize(body, 4); byte[] parent = body.getOptionalRaw(0); checkLength(parent, UniqueId.LENGTH); BdfList authorList = body.getList(1); Author author = clientHelper.parseAndValidateAuthor(authorList); String content = body.getString(2); checkLength(content, 0, MAX_FORUM_POST_BODY_LENGTH); byte[] sig = body.getRaw(3); checkLength(sig, 1, MAX_SIGNATURE_LENGTH); BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), parent, authorList, content); try { clientHelper.verifySignature(sig, SIGNING_LABEL_POST, signed, author.getPublicKey()); } catch (GeneralSecurityException e) { throw new InvalidMessageException(e); } BdfDictionary meta = new BdfDictionary(); Collection<MessageId> dependencies = Collections.emptyList(); meta.put(KEY_TIMESTAMP, m.getTimestamp()); if (parent != null) { meta.put(KEY_PARENT, parent); dependencies = Collections.singletonList(new MessageId(parent)); } meta.put(KEY_AUTHOR, authorList); meta.put(KEY_READ, false); return new BdfMessageContext(meta, dependencies); } ForumPostValidator(ClientHelper clientHelper,
			MetadataEncoder metadataEncoder, Clock clock);  }
ForumPostValidator extends BdfMessageValidator { @Override protected BdfMessageContext validateMessage(Message m, Group g, BdfList body) throws InvalidMessageException, FormatException { checkSize(body, 4); byte[] parent = body.getOptionalRaw(0); checkLength(parent, UniqueId.LENGTH); BdfList authorList = body.getList(1); Author author = clientHelper.parseAndValidateAuthor(authorList); String content = body.getString(2); checkLength(content, 0, MAX_FORUM_POST_BODY_LENGTH); byte[] sig = body.getRaw(3); checkLength(sig, 1, MAX_SIGNATURE_LENGTH); BdfList signed = BdfList.of(g.getId(), m.getTimestamp(), parent, authorList, content); try { clientHelper.verifySignature(sig, SIGNING_LABEL_POST, signed, author.getPublicKey()); } catch (GeneralSecurityException e) { throw new InvalidMessageException(e); } BdfDictionary meta = new BdfDictionary(); Collection<MessageId> dependencies = Collections.emptyList(); meta.put(KEY_TIMESTAMP, m.getTimestamp()); if (parent != null) { meta.put(KEY_PARENT, parent); dependencies = Collections.singletonList(new MessageId(parent)); } meta.put(KEY_AUTHOR, authorList); meta.put(KEY_READ, false); return new BdfMessageContext(meta, dependencies); } ForumPostValidator(ClientHelper clientHelper,
			MetadataEncoder metadataEncoder, Clock clock);   }