use of com.google.crypto.tink.prf.PrfSet in project tink by google.
the class PrfSetServiceImpl method compute.
/**
* Computes the output of one PRF.
*/
@Override
public void compute(PrfSetComputeRequest request, StreamObserver<PrfSetComputeResponse> responseObserver) {
PrfSetComputeResponse response;
try {
KeysetHandle keysetHandle = CleartextKeysetHandle.read(BinaryKeysetReader.withBytes(request.getKeyset().toByteArray()));
PrfSet prfSet = keysetHandle.getPrimitive(PrfSet.class);
Map<Integer, Prf> prfs = prfSet.getPrfs();
if (!prfs.containsKey(request.getKeyId())) {
response = PrfSetComputeResponse.newBuilder().setErr("Unknown Key ID.").build();
} else {
byte[] output = prfs.get(request.getKeyId()).compute(request.getInputData().toByteArray(), request.getOutputLength());
response = PrfSetComputeResponse.newBuilder().setOutput(ByteString.copyFrom(output)).build();
}
} catch (GeneralSecurityException | InvalidProtocolBufferException e) {
response = PrfSetComputeResponse.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.prf.PrfSet 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();
}
Aggregations