@Test public void nextFailure() throws Exception { when(mockStub.send(Matchers.<HandshakerReq>any())) .thenReturn(MockAltsHandshakerResp.getErrorResponse()); try { ByteBuffer inBytes = ByteBuffer.allocate(IN_BYTES_SIZE); handshaker.next(inBytes); fail("Exception expected"); } catch (GeneralSecurityException ex) { assertThat(ex).hasMessageThat().contains(MockAltsHandshakerResp.getTestErrorDetails()); } }
public ByteBuffer next(ByteBuffer inBytes) throws GeneralSecurityException { Preconditions.checkState(!isFinished(), "Handshake has already finished."); HandshakerReq.Builder req = HandshakerReq.newBuilder() .setNext( NextHandshakeMessageReq.newBuilder() .setInBytes(ByteString.copyFrom(inBytes.duplicate())) .build()); HandshakerResp resp; try { resp = handshakerStub.send(req.build()); } catch (IOException | InterruptedException e) { throw new GeneralSecurityException(e); } handleResponse(resp); inBytes.position(inBytes.position() + resp.getBytesConsumed()); return resp.getOutFrames().asReadOnlyByteBuffer(); }
AltsHandshakerClient { public ByteBuffer next(ByteBuffer inBytes) throws GeneralSecurityException { Preconditions.checkState(!isFinished(), "Handshake has already finished."); HandshakerReq.Builder req = HandshakerReq.newBuilder() .setNext( NextHandshakeMessageReq.newBuilder() .setInBytes(ByteString.copyFrom(inBytes.duplicate())) .build()); HandshakerResp resp; try { resp = handshakerStub.send(req.build()); } catch (IOException | InterruptedException e) { throw new GeneralSecurityException(e); } handleResponse(resp); inBytes.position(inBytes.position() + resp.getBytesConsumed()); return resp.getOutFrames().asReadOnlyByteBuffer(); } }
AltsHandshakerClient { public ByteBuffer next(ByteBuffer inBytes) throws GeneralSecurityException { Preconditions.checkState(!isFinished(), "Handshake has already finished."); HandshakerReq.Builder req = HandshakerReq.newBuilder() .setNext( NextHandshakeMessageReq.newBuilder() .setInBytes(ByteString.copyFrom(inBytes.duplicate())) .build()); HandshakerResp resp; try { resp = handshakerStub.send(req.build()); } catch (IOException | InterruptedException e) { throw new GeneralSecurityException(e); } handleResponse(resp); inBytes.position(inBytes.position() + resp.getBytesConsumed()); return resp.getOutFrames().asReadOnlyByteBuffer(); } AltsHandshakerClient(HandshakerServiceStub stub, AltsHandshakerOptions options); @VisibleForTesting  AltsHandshakerClient(AltsHandshakerStub handshakerStub, AltsHandshakerOptions options); }
AltsHandshakerClient { public ByteBuffer next(ByteBuffer inBytes) throws GeneralSecurityException { Preconditions.checkState(!isFinished(), "Handshake has already finished."); HandshakerReq.Builder req = HandshakerReq.newBuilder() .setNext( NextHandshakeMessageReq.newBuilder() .setInBytes(ByteString.copyFrom(inBytes.duplicate())) .build()); HandshakerResp resp; try { resp = handshakerStub.send(req.build()); } catch (IOException | InterruptedException e) { throw new GeneralSecurityException(e); } handleResponse(resp); inBytes.position(inBytes.position() + resp.getBytesConsumed()); return resp.getOutFrames().asReadOnlyByteBuffer(); } AltsHandshakerClient(HandshakerServiceStub stub, AltsHandshakerOptions options); @VisibleForTesting  AltsHandshakerClient(AltsHandshakerStub handshakerStub, AltsHandshakerOptions options); boolean isFinished(); HandshakerStatus getStatus(); HandshakerResult getResult(); byte[] getKey(); ByteBuffer startClientHandshake(); ByteBuffer startServerHandshake(ByteBuffer inBytes); ByteBuffer next(ByteBuffer inBytes); void close(); }
AltsHandshakerClient { public ByteBuffer next(ByteBuffer inBytes) throws GeneralSecurityException { Preconditions.checkState(!isFinished(), "Handshake has already finished."); HandshakerReq.Builder req = HandshakerReq.newBuilder() .setNext( NextHandshakeMessageReq.newBuilder() .setInBytes(ByteString.copyFrom(inBytes.duplicate())) .build()); HandshakerResp resp; try { resp = handshakerStub.send(req.build()); } catch (IOException | InterruptedException e) { throw new GeneralSecurityException(e); } handleResponse(resp); inBytes.position(inBytes.position() + resp.getBytesConsumed()); return resp.getOutFrames().asReadOnlyByteBuffer(); } AltsHandshakerClient(HandshakerServiceStub stub, AltsHandshakerOptions options); @VisibleForTesting  AltsHandshakerClient(AltsHandshakerStub handshakerStub, AltsHandshakerOptions options); boolean isFinished(); HandshakerStatus getStatus(); HandshakerResult getResult(); byte[] getKey(); ByteBuffer startClientHandshake(); ByteBuffer startServerHandshake(ByteBuffer inBytes); ByteBuffer next(ByteBuffer inBytes); void close();  }