@Test public void encryptPayloadRaw() { byte[] message = "HELLOW".getBytes(); byte[] encryptedKey = "encryptedKey".getBytes(); Nonce nonce = new Nonce("Nonce".getBytes()); PublicKey senderPublicKey = PublicKey.from("SenderPublicKey".getBytes()); List<PublicKey> recipientPublicKeys = Arrays.asList(PublicKey.from("RecipientPublicKey".getBytes())); RawTransaction rawTransaction = new RawTransaction(message, encryptedKey, nonce, senderPublicKey); EncodedPayload encodedPayload = Fixtures.createSample(); when(enclave.encryptPayload(any(RawTransaction.class), any(List.class))).thenReturn(encodedPayload); EncodedPayload result = enclaveClient.encryptPayload(rawTransaction, recipientPublicKeys); assertThat(result).isNotNull(); byte[] encodedResult = PayloadEncoder.create().encode(result); byte[] encodedEncodedPayload = PayloadEncoder.create().encode(encodedPayload); assertThat(encodedResult).isEqualTo(encodedEncodedPayload); verify(enclave).encryptPayload(any(RawTransaction.class), any(List.class)); }
@Override public EncodedPayload encryptPayload( byte[] message, PublicKey senderPublicKey, List<PublicKey> recipientPublicKeys) { return ClientCallback.execute( () -> { EnclavePayload enclavePayload = new EnclavePayload(); enclavePayload.setData(message); enclavePayload.setSenderKey(senderPublicKey.getKeyBytes()); enclavePayload.setRecipientPublicKeys( recipientPublicKeys.stream().map(PublicKey::getKeyBytes).collect(Collectors.toList())); Response response = client.target(uri).path("encrypt").request().post(Entity.json(enclavePayload)); validateResponseIsOk(response); byte[] result = response.readEntity(byte[].class); return PayloadEncoder.create().decode(result); }); }
RestfulEnclaveClient implements EnclaveClient { @Override public EncodedPayload encryptPayload( byte[] message, PublicKey senderPublicKey, List<PublicKey> recipientPublicKeys) { return ClientCallback.execute( () -> { EnclavePayload enclavePayload = new EnclavePayload(); enclavePayload.setData(message); enclavePayload.setSenderKey(senderPublicKey.getKeyBytes()); enclavePayload.setRecipientPublicKeys( recipientPublicKeys.stream().map(PublicKey::getKeyBytes).collect(Collectors.toList())); Response response = client.target(uri).path("encrypt").request().post(Entity.json(enclavePayload)); validateResponseIsOk(response); byte[] result = response.readEntity(byte[].class); return PayloadEncoder.create().decode(result); }); } }
RestfulEnclaveClient implements EnclaveClient { @Override public EncodedPayload encryptPayload( byte[] message, PublicKey senderPublicKey, List<PublicKey> recipientPublicKeys) { return ClientCallback.execute( () -> { EnclavePayload enclavePayload = new EnclavePayload(); enclavePayload.setData(message); enclavePayload.setSenderKey(senderPublicKey.getKeyBytes()); enclavePayload.setRecipientPublicKeys( recipientPublicKeys.stream().map(PublicKey::getKeyBytes).collect(Collectors.toList())); Response response = client.target(uri).path("encrypt").request().post(Entity.json(enclavePayload)); validateResponseIsOk(response); byte[] result = response.readEntity(byte[].class); return PayloadEncoder.create().decode(result); }); } RestfulEnclaveClient(Client client, URI uri);  RestfulEnclaveClient(Client client, URI uri, ExecutorService executorService); }
RestfulEnclaveClient implements EnclaveClient { @Override public EncodedPayload encryptPayload( byte[] message, PublicKey senderPublicKey, List<PublicKey> recipientPublicKeys) { return ClientCallback.execute( () -> { EnclavePayload enclavePayload = new EnclavePayload(); enclavePayload.setData(message); enclavePayload.setSenderKey(senderPublicKey.getKeyBytes()); enclavePayload.setRecipientPublicKeys( recipientPublicKeys.stream().map(PublicKey::getKeyBytes).collect(Collectors.toList())); Response response = client.target(uri).path("encrypt").request().post(Entity.json(enclavePayload)); validateResponseIsOk(response); byte[] result = response.readEntity(byte[].class); return PayloadEncoder.create().decode(result); }); } RestfulEnclaveClient(Client client, URI uri);  RestfulEnclaveClient(Client client, URI uri, ExecutorService executorService); @Override PublicKey defaultPublicKey(); @Override Set<PublicKey> getForwardingKeys(); @Override Set<PublicKey> getPublicKeys(); @Override EncodedPayload encryptPayload(
            byte[] message, PublicKey senderPublicKey, List<PublicKey> recipientPublicKeys); @Override EncodedPayload encryptPayload(RawTransaction rawTransaction, List<PublicKey> recipientPublicKeys); @Override RawTransaction encryptRawPayload(byte[] message, PublicKey sender); @Override byte[] unencryptTransaction(EncodedPayload payload, PublicKey providedKey); @Override byte[] createNewRecipientBox(final EncodedPayload payload, final PublicKey recipientKey); @Override Service.Status status(); }
RestfulEnclaveClient implements EnclaveClient { @Override public EncodedPayload encryptPayload( byte[] message, PublicKey senderPublicKey, List<PublicKey> recipientPublicKeys) { return ClientCallback.execute( () -> { EnclavePayload enclavePayload = new EnclavePayload(); enclavePayload.setData(message); enclavePayload.setSenderKey(senderPublicKey.getKeyBytes()); enclavePayload.setRecipientPublicKeys( recipientPublicKeys.stream().map(PublicKey::getKeyBytes).collect(Collectors.toList())); Response response = client.target(uri).path("encrypt").request().post(Entity.json(enclavePayload)); validateResponseIsOk(response); byte[] result = response.readEntity(byte[].class); return PayloadEncoder.create().decode(result); }); } RestfulEnclaveClient(Client client, URI uri);  RestfulEnclaveClient(Client client, URI uri, ExecutorService executorService); @Override PublicKey defaultPublicKey(); @Override Set<PublicKey> getForwardingKeys(); @Override Set<PublicKey> getPublicKeys(); @Override EncodedPayload encryptPayload(
            byte[] message, PublicKey senderPublicKey, List<PublicKey> recipientPublicKeys); @Override EncodedPayload encryptPayload(RawTransaction rawTransaction, List<PublicKey> recipientPublicKeys); @Override RawTransaction encryptRawPayload(byte[] message, PublicKey sender); @Override byte[] unencryptTransaction(EncodedPayload payload, PublicKey providedKey); @Override byte[] createNewRecipientBox(final EncodedPayload payload, final PublicKey recipientKey); @Override Service.Status status();  }