testing/java_src/java/com/google/crypto/tink/testing/JwtServiceImpl.java
/** Creates a signed compact JWT. */
Creates a signed compact JWT.
Creates a signed compact JWT .
@Override
  public void computeMacAndEncode(
      JwtSignRequest request, StreamObserver<JwtSignResponse> responseObserver) {
    JwtSignResponse response;
    try {
      KeysetHandle keysetHandle =
          CleartextKeysetHandle.read(
              BinaryKeysetReader.withBytes(request.getKeyset().toByteArray()));
      RawJwt rawJwt = convertJwtTokenToRawJwt(request.getRawJwt());
      JwtMac jwtMac = keysetHandle.getPrimitive(JwtMac.class);
      String signedCompactJwt = jwtMac.computeMacAndEncode(rawJwt);
      response = JwtSignResponse.newBuilder().setSignedCompactJwt(signedCompactJwt).build();
    } catch (GeneralSecurityException | InvalidProtocolBufferException e)  {
      response = JwtSignResponse.newBuilder().setErr(e.toString()).build();
    } catch (IOException e) {
      responseObserver.onError(Status.UNKNOWN.withDescription(e.getMessage()).asException());
      return;
    }
    responseObserver.onNext(response);
    responseObserver.onCompleted();
  }
@ Override public void computeMacAndEncode ( JwtSignRequest request , StreamObserver < JwtSignResponse > responseObserver ) { JwtSignResponse response ; try { KeysetHandle keysetHandle = CleartextKeysetHandle . read ( BinaryKeysetReader . withBytes ( request . getKeyset ( ) . toByteArray ( ) ) ) ; RawJwt rawJwt = convertJwtTokenToRawJwt ( request . getRawJwt ( ) ) ; JwtMac jwtMac = keysetHandle . getPrimitive ( JwtMac . class ) ; String signedCompactJwt = jwtMac . computeMacAndEncode ( rawJwt ) ; response = JwtSignResponse . newBuilder ( ) . setSignedCompactJwt ( signedCompactJwt ) . build ( ) ; } catch ( GeneralSecurityException | InvalidProtocolBufferException e ) { response = JwtSignResponse . newBuilder ( ) . setErr ( e . toString ( ) ) . build ( ) ; } catch ( IOException e ) { responseObserver . onError ( Status . UNKNOWN . withDescription ( e . getMessage ( ) ) . asException ( ) ) ; return ; } responseObserver . onNext ( response ) ; responseObserver . onCompleted ( ) ; }
Creates a signed compact JWT.
Creates a signed compact JWT .