Search in sources :

Example 1 with PrfSetKeyIdsResponse

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

the class TestingServicesTest method prfKeyIds_failsOnBadKeyset.

@Test
public void prfKeyIds_failsOnBadKeyset() throws Exception {
    byte[] badKeyset = "bad keyset".getBytes(UTF_8);
    PrfSetKeyIdsResponse keyIdsResponse = keyIds(prfSetStub, badKeyset);
    assertThat(keyIdsResponse.getErr()).isNotEmpty();
}
Also used : PrfSetKeyIdsResponse(com.google.crypto.tink.proto.testing.PrfSetKeyIdsResponse) Test(org.junit.Test)

Example 2 with PrfSetKeyIdsResponse

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

the class PrfSetServiceImpl method keyIds.

/**
 * Returns the key IDs of the keyset.
 */
@Override
public void keyIds(PrfSetKeyIdsRequest request, StreamObserver<PrfSetKeyIdsResponse> responseObserver) {
    PrfSetKeyIdsResponse response;
    try {
        KeysetHandle keysetHandle = CleartextKeysetHandle.read(BinaryKeysetReader.withBytes(request.getKeyset().toByteArray()));
        PrfSet prfSet = keysetHandle.getPrimitive(PrfSet.class);
        PrfSetKeyIdsResponse.Output output = PrfSetKeyIdsResponse.Output.newBuilder().setPrimaryKeyId(prfSet.getPrimaryId()).addAllKeyId(prfSet.getPrfs().keySet()).build();
        response = PrfSetKeyIdsResponse.newBuilder().setOutput(output).build();
    } catch (GeneralSecurityException | InvalidProtocolBufferException e) {
        response = PrfSetKeyIdsResponse.newBuilder().setErr(e.toString()).build();
    } catch (IOException e) {
        responseObserver.onError(Status.UNKNOWN.withDescription(e.getMessage()).asException());
        return;
    }
    responseObserver.onNext(response);
    responseObserver.onCompleted();
}
Also used : CleartextKeysetHandle(com.google.crypto.tink.CleartextKeysetHandle) KeysetHandle(com.google.crypto.tink.KeysetHandle) PrfSet(com.google.crypto.tink.prf.PrfSet) GeneralSecurityException(java.security.GeneralSecurityException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IOException(java.io.IOException) PrfSetKeyIdsResponse(com.google.crypto.tink.proto.testing.PrfSetKeyIdsResponse)

Example 3 with PrfSetKeyIdsResponse

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

the class TestingServicesTest method computePrf_success.

@Test
public void computePrf_success() throws Exception {
    byte[] template = KeyTemplateProtoConverter.toByteArray(HmacPrfKeyManager.hmacSha256Template());
    byte[] inputData = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
    int outputLength = 15;
    KeysetGenerateResponse keysetResponse = generateKeyset(keysetStub, template);
    assertThat(keysetResponse.getErr()).isEmpty();
    byte[] keyset = keysetResponse.getKeyset().toByteArray();
    PrfSetKeyIdsResponse keyIdsResponse = keyIds(prfSetStub, keyset);
    assertThat(keyIdsResponse.getErr()).isEmpty();
    int primaryKeyId = keyIdsResponse.getOutput().getPrimaryKeyId();
    PrfSetComputeResponse computeResponse = computePrf(prfSetStub, keyset, primaryKeyId, inputData, outputLength);
    assertThat(computeResponse.getErr()).isEmpty();
    assertThat(computeResponse.getOutput().size()).isEqualTo(outputLength);
}
Also used : PrfSetComputeResponse(com.google.crypto.tink.proto.testing.PrfSetComputeResponse) KeysetGenerateResponse(com.google.crypto.tink.proto.testing.KeysetGenerateResponse) PrfSetKeyIdsResponse(com.google.crypto.tink.proto.testing.PrfSetKeyIdsResponse) Test(org.junit.Test)

Example 4 with PrfSetKeyIdsResponse

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

the class TestingServicesTest method computePrf_failsOnBadOutputLength.

@Test
public void computePrf_failsOnBadOutputLength() throws Exception {
    byte[] template = KeyTemplateProtoConverter.toByteArray(HmacPrfKeyManager.hmacSha256Template());
    byte[] inputData = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
    int outputLength = 12345;
    KeysetGenerateResponse keysetResponse = generateKeyset(keysetStub, template);
    assertThat(keysetResponse.getErr()).isEmpty();
    byte[] keyset = keysetResponse.getKeyset().toByteArray();
    PrfSetKeyIdsResponse keyIdsResponse = keyIds(prfSetStub, keyset);
    assertThat(keyIdsResponse.getErr()).isEmpty();
    int primaryKeyId = keyIdsResponse.getOutput().getPrimaryKeyId();
    PrfSetComputeResponse computeResponse = computePrf(prfSetStub, keyset, primaryKeyId, inputData, outputLength);
    assertThat(computeResponse.getErr()).isNotEmpty();
}
Also used : PrfSetComputeResponse(com.google.crypto.tink.proto.testing.PrfSetComputeResponse) KeysetGenerateResponse(com.google.crypto.tink.proto.testing.KeysetGenerateResponse) PrfSetKeyIdsResponse(com.google.crypto.tink.proto.testing.PrfSetKeyIdsResponse) Test(org.junit.Test)

Aggregations

PrfSetKeyIdsResponse (com.google.crypto.tink.proto.testing.PrfSetKeyIdsResponse)4 Test (org.junit.Test)3 KeysetGenerateResponse (com.google.crypto.tink.proto.testing.KeysetGenerateResponse)2 PrfSetComputeResponse (com.google.crypto.tink.proto.testing.PrfSetComputeResponse)2 CleartextKeysetHandle (com.google.crypto.tink.CleartextKeysetHandle)1 KeysetHandle (com.google.crypto.tink.KeysetHandle)1 PrfSet (com.google.crypto.tink.prf.PrfSet)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1