* CertTokenResponse ::= SEQUENCE { * status PKIStatusInfo, * certToken [0] CertToken OPTIONAL * } * * * @package asn1 * @subpackage gt */ class GTCertTokenResponse { private $status; private $token; /** * Constructs a new instance of GTCertTokenResponse. */ public function __construct() { } /** * Decodes the given ASN1Sequence as GTCertTokenResponse. * * @throws GTException * @param ASN1Sequence $object GTCertTokenResponse encoded as ASN1Sequence * @return void */ public function decode($object) { if (!$object instanceof ASN1Sequence) { throw new GTException("object must be an instance of ASN1Sequence"); } if ($object->getObjectCount() < 1 || $object->getObjectCount() > 2) { throw new GTException("invalid sequence size"); } $status = new PKIStatusInfo(); $status->decode($object->getObjectAt(0)); $this->status = $status; $code = $this->getStatusCode(); if ($code == 0 || $code == 1) { if ($object->getObjectCount() != 2) { throw new GTException("token is missing"); } $tag = $object->getObjectAt(1); if ($tag->getTagValue() != 0) { throw new GTException("Unexpected tag value: " . $tag->getTagValue()); } $token = new GTCertToken(); $token->decode($tag->getObjectAs(ASN1_TAG_SEQUENCE)); $this->token = $token; } else if ($code >= 2 && $code <= 5) { if ($object->getObjectCount() == 2) { throw new GTException("unexpected timestamp token"); } } else { throw new GTException("invalid status code: {$code}"); } } /** * Gets the statsu. * * @return PKIStatusInfo status */ public function getStatus() { return $this->status; } /** * Gets the status code. * * @return int status code */ public function getStatusCode() { return $this->status->getStatus(); } /** * Gets the failure code. * * @throws GTException * @return string failure code */ public function getFailCode() { $info = $this->status->getFailInfo(); if (empty($info)) { return -1; } $code = strpos($this->status->getFailInfo(), '1'); if ($code === false) { return -1; } return $code; } /** * Gets the cert token. * * @return GTCertToken token */ public function getToken() { return $this->token; } } ?>