class ToBeSignedJwt {

  String compact(String alg) {
    JSONObject copy;

    try {
      copy = new JSONObject(this.header.toString());
      copy.put(JwtNames.HEADER_ALGORITHM, alg);
    } catch (JSONException ex) {
      // Should never happen.
      throw new IllegalStateException(ex);
    }

    String headerStr = Base64.urlSafeEncode(copy.toString().getBytes(UTF_8));
    String payloadStr = Base64.urlSafeEncode(this.payload.toString().getBytes(UTF_8));
    return headerStr + "." + payloadStr;
  }

  private  ToBeSignedJwt(Builder builder);

}