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();
}
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();
}
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);
}
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();
}
Aggregations