TimeStampResponseGenerator (Bouncy Castle Library 1.52 API Specification)
Date: 2015-03-01

org.bouncycastle.tsp

## Class TimeStampResponseGenerator

- java.lang.Object
- - org.bouncycastle.tsp.TimeStampResponseGenerator

-     public class TimeStampResponseGenerator
      extends java.lang.Object

  Generator for RFC 3161 Time Stamp Responses.

  New generate methods have been introduced to give people more control over what ends up in the message. Unfortunately it turns out that in some cases fields like statusString must be left out otherwise a an otherwise valid timestamp will be rejected.

  If you're after the most control with generating a response use:

          TimeStampResponse tsResp;

          try
          {
             tsResp = tsRespGen.generateGrantedResponse(request, new BigInteger("23"), new Date());
          }
          catch (Exception e)
          {
              tsResp = tsRespGen.generateRejectedResponse(e);
          }

  The generate method does this, but provides a status string of "Operation Okay".

  It should be pointed out that generateRejectedResponse() may also, on very rare occasions throw a TSPException. In the event that happens, there's a serious internal problem with your responder.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TimeStampResponseGenerator(TimeStampTokenGenerator tokenGenerator, java.util.Set acceptedAlgorithms)`
    `TimeStampResponseGenerator(TimeStampTokenGenerator tokenGenerator, java.util.Set acceptedAlgorithms, java.util.Set acceptedPolicies)`
    `TimeStampResponseGenerator(TimeStampTokenGenerator tokenGenerator, java.util.Set acceptedAlgorithms, java.util.Set acceptedPolicies, java.util.Set acceptedExtensions)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `TimeStampResponse` | `generate(TimeStampRequest request, java.math.BigInteger serialNumber, java.util.Date genTime)` Return an appropriate TimeStampResponse.
    `TimeStampResponse` | `generateFailResponse(int status, int failInfoField, java.lang.String statusString)` Generate a non-granted TimeStampResponse with chosen status and FailInfoField.
    `TimeStampResponse` | `generateGrantedResponse(TimeStampRequest request, java.math.BigInteger serialNumber, java.util.Date genTime)` Return a granted response, if the passed in request passes validation.
    `TimeStampResponse` | `generateGrantedResponse(TimeStampRequest request, java.math.BigInteger serialNumber, java.util.Date genTime, java.lang.String statusString)` Return a granted response, if the passed in request passes validation with the passed in status string.
    `TimeStampResponse` | `generateRejectedResponse(java.lang.Exception exception)` Generate a generic rejection response based on a TSPValidationException or an Exception.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TimeStampResponseGenerator

          public TimeStampResponseGenerator(TimeStampTokenGenerator tokenGenerator,
                                    java.util.Set acceptedAlgorithms)

      Parameters:
        `tokenGenerator` -
        `acceptedAlgorithms` - a set of OIDs giving accepted algorithms.

    - #### TimeStampResponseGenerator

          public TimeStampResponseGenerator(TimeStampTokenGenerator tokenGenerator,
                                    java.util.Set acceptedAlgorithms,
                                    java.util.Set acceptedPolicies)

      Parameters:
        `tokenGenerator` -
        `acceptedAlgorithms` - a set of OIDs giving accepted algorithms.
        `acceptedPolicies` - if non-null a set of policies OIDs we are willing to sign under.

    - #### TimeStampResponseGenerator

          public TimeStampResponseGenerator(TimeStampTokenGenerator tokenGenerator,
                                    java.util.Set acceptedAlgorithms,
                                    java.util.Set acceptedPolicies,
                                    java.util.Set acceptedExtensions)

      Parameters:
        `tokenGenerator` -
        `acceptedAlgorithms` - a set of OIDs giving accepted algorithms.
        `acceptedPolicies` - if non-null a set of policies OIDs we are willing to sign under.
        `acceptedExtensions` - if non-null a set of extensions OIDs we are willing to accept.

  - ### Method Detail

    - #### generate

          public TimeStampResponse generate(TimeStampRequest request,
                                   java.math.BigInteger serialNumber,
                                   java.util.Date genTime)
                                     throws TSPException

      Return an appropriate TimeStampResponse.

      If genTime is null a timeNotAvailable error response will be returned. Calling generate() is the equivalent of:

              TimeStampResponse tsResp;

              try
              {
                 tsResp = tsRespGen.generateGrantedResponse(request, serialNumber, genTime, "Operation Okay");
              }
              catch (Exception e)
              {
                  tsResp = tsRespGen.generateRejectedResponse(e);
              }

      Parameters:
        `request` - the request this response is for.
        `serialNumber` - serial number for the response token.
        `genTime` - generation time for the response token.
      Returns:
        a TimeStampResponse.
      Throws:
        `TSPException`

    - #### generateGrantedResponse

          public TimeStampResponse generateGrantedResponse(TimeStampRequest request,
                                                  java.math.BigInteger serialNumber,
                                                  java.util.Date genTime)
                                                    throws TSPException

      Return a granted response, if the passed in request passes validation.

      If genTime is null a timeNotAvailable or a validation exception occurs a TSPValidationException will be thrown. The parent TSPException will only occur on some sort of system failure.

      Parameters:
        `request` - the request this response is for.
        `serialNumber` - serial number for the response token.
        `genTime` - generation time for the response token.
      Returns:
        the TimeStampResponse with a status of PKIStatus.GRANTED
      Throws:
        `TSPException` - on validation exception or internal error.

    - #### generateGrantedResponse

          public TimeStampResponse generateGrantedResponse(TimeStampRequest request,
                                                  java.math.BigInteger serialNumber,
                                                  java.util.Date genTime,
                                                  java.lang.String statusString)
                                                    throws TSPException

      Return a granted response, if the passed in request passes validation with the passed in status string.

      If genTime is null a timeNotAvailable or a validation exception occurs a TSPValidationException will be thrown. The parent TSPException will only occur on some sort of system failure.

      Parameters:
        `request` - the request this response is for.
        `serialNumber` - serial number for the response token.
        `genTime` - generation time for the response token.
      Returns:
        the TimeStampResponse with a status of PKIStatus.GRANTED
      Throws:
        `TSPException` - on validation exception or internal error.

    - #### generateRejectedResponse

          public TimeStampResponse generateRejectedResponse(java.lang.Exception exception)
                                                     throws TSPException

      Generate a generic rejection response based on a TSPValidationException or an Exception. Exceptions which are not an instance of TSPValidationException will be treated as systemFailure. The return value of exception.getMessage() will be used as the status string for the response.
      Parameters:
        `exception` - the exception thrown on validating the request.
      Returns:
        a TimeStampResponse.
      Throws:
        `TSPException` - if a failure response cannot be generated.

    - #### generateFailResponse

          public TimeStampResponse generateFailResponse(int status,
                                               int failInfoField,
                                               java.lang.String statusString)
                                                 throws TSPException

      Generate a non-granted TimeStampResponse with chosen status and FailInfoField.
      Parameters:
        `status` - the PKIStatus to set.
        `failInfoField` - the FailInfoField to set.
        `statusString` - an optional string describing the failure.
      Returns:
        a TimeStampResponse with a failInfoField and optional statusString
      Throws:
        `TSPException` - in case the response could not be created