@Test public void encryptPayloadToRaw() { byte[] message = "HELLOW".getBytes(); PublicKey senderPublicKey = PublicKey.from("SenderPublicKey".getBytes()); byte[] encryptedKey = "encryptedKey".getBytes(); Nonce nonce = new Nonce("Nonce".getBytes()); RawTransaction rawTransaction = new RawTransaction(message, encryptedKey, nonce, senderPublicKey); when(enclave.encryptRawPayload(message, senderPublicKey)).thenReturn(rawTransaction); RawTransaction result = enclaveClient.encryptRawPayload(message, senderPublicKey); assertThat(result).isNotNull(); assertThat(result).isEqualTo(rawTransaction); verify(enclave).encryptRawPayload(message, senderPublicKey); }
@Override public RawTransaction encryptRawPayload(byte[] message, PublicKey sender) { return ClientCallback.execute( () -> { EnclavePayload enclavePayload = new EnclavePayload(); enclavePayload.setData(message); enclavePayload.setSenderKey(sender.getKeyBytes()); Response response = client.target(uri) .path("encrypt") .path("toraw") .request() .post(Entity.json(enclavePayload)); validateResponseIsOk(response); EnclaveRawPayload enclaveRawPayload = response.readEntity(EnclaveRawPayload.class); byte[] encryptedPayload = enclaveRawPayload.getEncryptedPayload(); byte[] encryptedKey = enclaveRawPayload.getEncryptedKey(); Nonce nonce = new Nonce(enclaveRawPayload.getNonce()); PublicKey senderKey = PublicKey.from(enclaveRawPayload.getFrom()); return new RawTransaction(encryptedPayload, encryptedKey, nonce, senderKey); }); }
RestfulEnclaveClient implements EnclaveClient { @Override public RawTransaction encryptRawPayload(byte[] message, PublicKey sender) { return ClientCallback.execute( () -> { EnclavePayload enclavePayload = new EnclavePayload(); enclavePayload.setData(message); enclavePayload.setSenderKey(sender.getKeyBytes()); Response response = client.target(uri) .path("encrypt") .path("toraw") .request() .post(Entity.json(enclavePayload)); validateResponseIsOk(response); EnclaveRawPayload enclaveRawPayload = response.readEntity(EnclaveRawPayload.class); byte[] encryptedPayload = enclaveRawPayload.getEncryptedPayload(); byte[] encryptedKey = enclaveRawPayload.getEncryptedKey(); Nonce nonce = new Nonce(enclaveRawPayload.getNonce()); PublicKey senderKey = PublicKey.from(enclaveRawPayload.getFrom()); return new RawTransaction(encryptedPayload, encryptedKey, nonce, senderKey); }); } }
RestfulEnclaveClient implements EnclaveClient { @Override public RawTransaction encryptRawPayload(byte[] message, PublicKey sender) { return ClientCallback.execute( () -> { EnclavePayload enclavePayload = new EnclavePayload(); enclavePayload.setData(message); enclavePayload.setSenderKey(sender.getKeyBytes()); Response response = client.target(uri) .path("encrypt") .path("toraw") .request() .post(Entity.json(enclavePayload)); validateResponseIsOk(response); EnclaveRawPayload enclaveRawPayload = response.readEntity(EnclaveRawPayload.class); byte[] encryptedPayload = enclaveRawPayload.getEncryptedPayload(); byte[] encryptedKey = enclaveRawPayload.getEncryptedKey(); Nonce nonce = new Nonce(enclaveRawPayload.getNonce()); PublicKey senderKey = PublicKey.from(enclaveRawPayload.getFrom()); return new RawTransaction(encryptedPayload, encryptedKey, nonce, senderKey); }); } RestfulEnclaveClient(Client client, URI uri);  RestfulEnclaveClient(Client client, URI uri, ExecutorService executorService); }
RestfulEnclaveClient implements EnclaveClient { @Override public RawTransaction encryptRawPayload(byte[] message, PublicKey sender) { return ClientCallback.execute( () -> { EnclavePayload enclavePayload = new EnclavePayload(); enclavePayload.setData(message); enclavePayload.setSenderKey(sender.getKeyBytes()); Response response = client.target(uri) .path("encrypt") .path("toraw") .request() .post(Entity.json(enclavePayload)); validateResponseIsOk(response); EnclaveRawPayload enclaveRawPayload = response.readEntity(EnclaveRawPayload.class); byte[] encryptedPayload = enclaveRawPayload.getEncryptedPayload(); byte[] encryptedKey = enclaveRawPayload.getEncryptedKey(); Nonce nonce = new Nonce(enclaveRawPayload.getNonce()); PublicKey senderKey = PublicKey.from(enclaveRawPayload.getFrom()); return new RawTransaction(encryptedPayload, encryptedKey, nonce, senderKey); }); } 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 RawTransaction encryptRawPayload(byte[] message, PublicKey sender) { return ClientCallback.execute( () -> { EnclavePayload enclavePayload = new EnclavePayload(); enclavePayload.setData(message); enclavePayload.setSenderKey(sender.getKeyBytes()); Response response = client.target(uri) .path("encrypt") .path("toraw") .request() .post(Entity.json(enclavePayload)); validateResponseIsOk(response); EnclaveRawPayload enclaveRawPayload = response.readEntity(EnclaveRawPayload.class); byte[] encryptedPayload = enclaveRawPayload.getEncryptedPayload(); byte[] encryptedKey = enclaveRawPayload.getEncryptedKey(); Nonce nonce = new Nonce(enclaveRawPayload.getNonce()); PublicKey senderKey = PublicKey.from(enclaveRawPayload.getFrom()); return new RawTransaction(encryptedPayload, encryptedKey, nonce, senderKey); }); } 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();  }