github.com/clocklock/go-rfc3161@v0.0.0-20160419203229-5ea544d9dee0/status.go (about)

     1  package rfc3161
     2  
     3  // PKIStatusInfo contains complete information about the status of the Time Stamp Response
     4  type PKIStatusInfo struct {
     5  	Status       PKIStatus
     6  	StatusString string         `asn1:"optional,utf8"`
     7  	FailInfo     PKIFailureInfo `asn1:"optional"`
     8  }
     9  
    10  func (si *PKIStatusInfo) Error() string {
    11  	var output string
    12  	output += si.Status.Error()
    13  	if si.Status.IsError() {
    14  		output += ": " + si.FailInfo.Error()
    15  	}
    16  	if si.StatusString != "" {
    17  		output += ": " + si.StatusString
    18  	}
    19  	return output
    20  }
    21  
    22  // PKIStatus carries the specific status code about the status of the Time Stamp Response.
    23  type PKIStatus int
    24  
    25  // When the status contains the value zero or one, a TimeStampToken MUST
    26  // be present.  When status contains a value other than zero or one, a
    27  // TimeStampToken MUST NOT be present.  One of the following values MUST
    28  //  be contained in status
    29  const (
    30  	StatusGranted                = iota // When the PKIStatus contains the value zero a TimeStampToken, as requested, is present.
    31  	StatusGrantedWithMods               // When the PKIStatus contains the value one a TimeStampToken, with modifications, is present.
    32  	StatusRejection                     // When the request is invalid or otherwise rejected.
    33  	StatusWaiting                       // When the request is being processed and the client should check back later.
    34  	StatusRevocationWarning             // Warning that a revocation is imminent.
    35  	StatusRevocationNotification        // Notification that a revocation has occurred.
    36  )
    37  
    38  // IsError checks if the given Status is an error
    39  func (status PKIStatus) IsError() bool {
    40  	return (status != StatusGranted && status != StatusGrantedWithMods && status != StatusWaiting)
    41  }
    42  
    43  func (status PKIStatus) Error() string {
    44  	switch status {
    45  	case StatusGranted:
    46  		return "A TimeStampToken, as requested, is present"
    47  	case StatusGrantedWithMods:
    48  		return "A TimeStampToken, with modifications, is present"
    49  	case StatusRejection:
    50  		return "The request is invalid or otherwise rejected"
    51  	case StatusWaiting:
    52  		return "The request is being processed and the client should check back later"
    53  	case StatusRevocationWarning:
    54  		return "A revocation is imminent"
    55  	case StatusRevocationNotification:
    56  		return "A revocation has occurred"
    57  	default:
    58  		return "Invalid PKIStatus"
    59  	}
    60  }
    61  
    62  // PKIFailureInfo as defined by RFC 3161 2.4.2
    63  type PKIFailureInfo int
    64  
    65  // When the TimeStampToken is not present, the failInfo indicates the reason why the time-stamp
    66  // request was rejected and may be one of the following values.
    67  const (
    68  	FailureBadAlg               = 0  // Unrecognized or unsupported Algorithm Identifier.
    69  	FailureBadRequest           = 2  // Transaction not permitted or supported.
    70  	FailureDataFormat           = 5  // The data submitted has the wrong format.
    71  	FailureTimeNotAvailabe      = 14 // The TSA's time source is not available.
    72  	FailureUnacceptedPolicy     = 15 // The requested TSA policy is not supported by the TSA.
    73  	FailureUunacceptedExtension = 16 // The requested extension is not supported by the TSA.
    74  	FailureAddInfoNotAvailable  = 17 // The additional information requested could not be understood or is not available.
    75  	FailureSystemFailure        = 25 // The request cannot be handled due to system failure.
    76  )
    77  
    78  func (fi PKIFailureInfo) Error() string {
    79  	switch fi {
    80  	case FailureBadAlg:
    81  		return "Unrecognized or unsupported Algorithm Identifier"
    82  	case FailureBadRequest:
    83  		return "Transaction not permitted or supported"
    84  	case FailureDataFormat:
    85  		return "The data submitted has the wrong format"
    86  	case FailureTimeNotAvailabe:
    87  		return "The TSA's time source is not available"
    88  	case FailureUnacceptedPolicy:
    89  		return "The requested TSA policy is not supported by the TSA"
    90  	case FailureUunacceptedExtension:
    91  		return "The requested extension is not supported by the TSA"
    92  	case FailureAddInfoNotAvailable:
    93  		return "The additional information requested could not be understood or is not available"
    94  	case FailureSystemFailure:
    95  		return "The request cannot be handled due to system failure"
    96  	default:
    97  		return "Invalid PKIFailureInfo"
    98  	}
    99  }