@Test public void testVerifyWrongSignature() throws Exception { byte[] signature = getRandomBytes(MAX_SIGNATURE_LENGTH); byte[] publicKey = getRandomBytes(42); byte[] signed = expectToByteArray(list); context.checking(new Expectations() {{ oneOf(cryptoComponent).verifySignature(signature, label, signed, publicKey); will(returnValue(false)); }}); try { clientHelper.verifySignature(signature, label, list, publicKey); fail(); } catch (GeneralSecurityException e) { context.assertIsSatisfied(); } }
@Override public void verifySignature(byte[] signature, String label, BdfList signed, byte[] publicKey) throws FormatException, GeneralSecurityException { if (!crypto.verifySignature(signature, label, toByteArray(signed), publicKey)) { throw new GeneralSecurityException("Invalid signature"); } }
ClientHelperImpl implements ClientHelper { @Override public void verifySignature(byte[] signature, String label, BdfList signed, byte[] publicKey) throws FormatException, GeneralSecurityException { if (!crypto.verifySignature(signature, label, toByteArray(signed), publicKey)) { throw new GeneralSecurityException("Invalid signature"); } } }
ClientHelperImpl implements ClientHelper { @Override public void verifySignature(byte[] signature, String label, BdfList signed, byte[] publicKey) throws FormatException, GeneralSecurityException { if (!crypto.verifySignature(signature, label, toByteArray(signed), publicKey)) { throw new GeneralSecurityException("Invalid signature"); } } @Inject  ClientHelperImpl(DatabaseComponent db, MessageFactory messageFactory,
			BdfReaderFactory bdfReaderFactory,
			BdfWriterFactory bdfWriterFactory, MetadataParser metadataParser,
			MetadataEncoder metadataEncoder, CryptoComponent crypto,
			AuthorFactory authorFactory); }
ClientHelperImpl implements ClientHelper { @Override public void verifySignature(byte[] signature, String label, BdfList signed, byte[] publicKey) throws FormatException, GeneralSecurityException { if (!crypto.verifySignature(signature, label, toByteArray(signed), publicKey)) { throw new GeneralSecurityException("Invalid signature"); } } @Inject  ClientHelperImpl(DatabaseComponent db, MessageFactory messageFactory,
			BdfReaderFactory bdfReaderFactory,
			BdfWriterFactory bdfWriterFactory, MetadataParser metadataParser,
			MetadataEncoder metadataEncoder, CryptoComponent crypto,
			AuthorFactory authorFactory); @Override void addLocalMessage(Message m, BdfDictionary metadata,
			boolean shared); @Override void addLocalMessage(Transaction txn, Message m,
			BdfDictionary metadata, boolean shared); @Override Message createMessage(GroupId g, long timestamp, BdfList body); @Override Message createMessageForStoringMetadata(GroupId g); @Override Message getMessage(MessageId m); @Override Message getMessage(Transaction txn, MessageId m); @Override BdfList getMessageAsList(MessageId m); @Override BdfList getMessageAsList(Transaction txn, MessageId m); @Override BdfDictionary getGroupMetadataAsDictionary(GroupId g); @Override BdfDictionary getGroupMetadataAsDictionary(Transaction txn,
			GroupId g); @Override BdfDictionary getMessageMetadataAsDictionary(MessageId m); @Override BdfDictionary getMessageMetadataAsDictionary(Transaction txn,
			MessageId m); @Override Map<MessageId, BdfDictionary> getMessageMetadataAsDictionary(
			GroupId g); @Override Map<MessageId, BdfDictionary> getMessageMetadataAsDictionary(
			Transaction txn, GroupId g); @Override Map<MessageId, BdfDictionary> getMessageMetadataAsDictionary(
			GroupId g, BdfDictionary query); @Override Map<MessageId, BdfDictionary> getMessageMetadataAsDictionary(
			Transaction txn, GroupId g, BdfDictionary query); @Override void mergeGroupMetadata(GroupId g, BdfDictionary metadata); @Override void mergeGroupMetadata(Transaction txn, GroupId g,
			BdfDictionary metadata); @Override void mergeMessageMetadata(MessageId m, BdfDictionary metadata); @Override void mergeMessageMetadata(Transaction txn, MessageId m,
			BdfDictionary metadata); @Override byte[] toByteArray(BdfDictionary dictionary); @Override byte[] toByteArray(BdfList list); @Override BdfDictionary toDictionary(byte[] b, int off, int len); @Override BdfDictionary toDictionary(TransportProperties transportProperties); @Override BdfDictionary toDictionary(
			Map<TransportId, TransportProperties> map); @Override BdfList toList(byte[] b, int off, int len); @Override BdfList toList(byte[] b); @Override BdfList toList(Message m); @Override BdfList toList(Author a); @Override byte[] sign(String label, BdfList toSign, byte[] privateKey); @Override void verifySignature(byte[] signature, String label, BdfList signed,
			byte[] publicKey); @Override Author parseAndValidateAuthor(BdfList author); @Override TransportProperties parseAndValidateTransportProperties(
			BdfDictionary properties); @Override Map<TransportId, TransportProperties> parseAndValidateTransportPropertiesMap(
			BdfDictionary properties); }
ClientHelperImpl implements ClientHelper { @Override public void verifySignature(byte[] signature, String label, BdfList signed, byte[] publicKey) throws FormatException, GeneralSecurityException { if (!crypto.verifySignature(signature, label, toByteArray(signed), publicKey)) { throw new GeneralSecurityException("Invalid signature"); } } @Inject  ClientHelperImpl(DatabaseComponent db, MessageFactory messageFactory,
			BdfReaderFactory bdfReaderFactory,
			BdfWriterFactory bdfWriterFactory, MetadataParser metadataParser,
			MetadataEncoder metadataEncoder, CryptoComponent crypto,
			AuthorFactory authorFactory); @Override void addLocalMessage(Message m, BdfDictionary metadata,
			boolean shared); @Override void addLocalMessage(Transaction txn, Message m,
			BdfDictionary metadata, boolean shared); @Override Message createMessage(GroupId g, long timestamp, BdfList body); @Override Message createMessageForStoringMetadata(GroupId g); @Override Message getMessage(MessageId m); @Override Message getMessage(Transaction txn, MessageId m); @Override BdfList getMessageAsList(MessageId m); @Override BdfList getMessageAsList(Transaction txn, MessageId m); @Override BdfDictionary getGroupMetadataAsDictionary(GroupId g); @Override BdfDictionary getGroupMetadataAsDictionary(Transaction txn,
			GroupId g); @Override BdfDictionary getMessageMetadataAsDictionary(MessageId m); @Override BdfDictionary getMessageMetadataAsDictionary(Transaction txn,
			MessageId m); @Override Map<MessageId, BdfDictionary> getMessageMetadataAsDictionary(
			GroupId g); @Override Map<MessageId, BdfDictionary> getMessageMetadataAsDictionary(
			Transaction txn, GroupId g); @Override Map<MessageId, BdfDictionary> getMessageMetadataAsDictionary(
			GroupId g, BdfDictionary query); @Override Map<MessageId, BdfDictionary> getMessageMetadataAsDictionary(
			Transaction txn, GroupId g, BdfDictionary query); @Override void mergeGroupMetadata(GroupId g, BdfDictionary metadata); @Override void mergeGroupMetadata(Transaction txn, GroupId g,
			BdfDictionary metadata); @Override void mergeMessageMetadata(MessageId m, BdfDictionary metadata); @Override void mergeMessageMetadata(Transaction txn, MessageId m,
			BdfDictionary metadata); @Override byte[] toByteArray(BdfDictionary dictionary); @Override byte[] toByteArray(BdfList list); @Override BdfDictionary toDictionary(byte[] b, int off, int len); @Override BdfDictionary toDictionary(TransportProperties transportProperties); @Override BdfDictionary toDictionary(
			Map<TransportId, TransportProperties> map); @Override BdfList toList(byte[] b, int off, int len); @Override BdfList toList(byte[] b); @Override BdfList toList(Message m); @Override BdfList toList(Author a); @Override byte[] sign(String label, BdfList toSign, byte[] privateKey); @Override void verifySignature(byte[] signature, String label, BdfList signed,
			byte[] publicKey); @Override Author parseAndValidateAuthor(BdfList author); @Override TransportProperties parseAndValidateTransportProperties(
			BdfDictionary properties); @Override Map<TransportId, TransportProperties> parseAndValidateTransportPropertiesMap(
			BdfDictionary properties);  }