Search in sources :

Example 1 with KeysetTemplateResponse

use of com.google.crypto.tink.proto.testing.KeysetTemplateResponse in project tink by google.

the class KeysetServiceImpl method getTemplate.

@Override
public void getTemplate(KeysetTemplateRequest request, StreamObserver<KeysetTemplateResponse> responseObserver) {
    KeysetTemplateResponse response;
    try {
        KeyTemplate template = KeyTemplates.get(request.getTemplateName());
        response = KeysetTemplateResponse.newBuilder().setKeyTemplate(ByteString.copyFrom(KeyTemplateProtoConverter.toByteArray(template))).build();
    } catch (GeneralSecurityException e) {
        response = KeysetTemplateResponse.newBuilder().setErr(e.toString()).build();
    }
    responseObserver.onNext(response);
    responseObserver.onCompleted();
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) KeysetTemplateResponse(com.google.crypto.tink.proto.testing.KeysetTemplateResponse) KeyTemplate(com.google.crypto.tink.KeyTemplate)

Example 2 with KeysetTemplateResponse

use of com.google.crypto.tink.proto.testing.KeysetTemplateResponse in project tink by google.

the class TestingServicesTest method template_success.

@Test
public void template_success() throws Exception {
    KeysetTemplateRequest request = KeysetTemplateRequest.newBuilder().setTemplateName("AES256_GCM").build();
    KeysetTemplateResponse response = keysetStub.getTemplate(request);
    assertThat(response.getErr()).isEmpty();
    KeyTemplate template = KeyTemplateProtoConverter.fromByteArray(response.getKeyTemplate().toByteArray());
    assertThat(template.getTypeUrl()).isEqualTo("type.googleapis.com/google.crypto.tink.AesGcmKey");
}
Also used : KeysetTemplateResponse(com.google.crypto.tink.proto.testing.KeysetTemplateResponse) KeysetTemplateRequest(com.google.crypto.tink.proto.testing.KeysetTemplateRequest) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 3 with KeysetTemplateResponse

use of com.google.crypto.tink.proto.testing.KeysetTemplateResponse in project tink by google.

the class TestingServicesTest method template_not_found.

@Test
public void template_not_found() throws Exception {
    KeysetTemplateRequest request = KeysetTemplateRequest.newBuilder().setTemplateName("UNKNOWN_TEMPLATE").build();
    KeysetTemplateResponse response = keysetStub.getTemplate(request);
    assertThat(response.getErr()).isNotEmpty();
}
Also used : KeysetTemplateResponse(com.google.crypto.tink.proto.testing.KeysetTemplateResponse) KeysetTemplateRequest(com.google.crypto.tink.proto.testing.KeysetTemplateRequest) Test(org.junit.Test)

Aggregations

KeysetTemplateResponse (com.google.crypto.tink.proto.testing.KeysetTemplateResponse)3 KeyTemplate (com.google.crypto.tink.KeyTemplate)2 KeysetTemplateRequest (com.google.crypto.tink.proto.testing.KeysetTemplateRequest)2 Test (org.junit.Test)2 GeneralSecurityException (java.security.GeneralSecurityException)1