1<?php
2/*
3 * Copyright 2008-2010 GuardTime AS
4 *
5 * This file is part of the GuardTime PHP SDK.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20/**
21 * @package asn1
22 * @subpackage cmp
23 */
24
25/**
26 * PKIStatusInfo implementation.
27 *
28 *<pre>
29 * PKIStatusInfo ::= SEQUENCE {
30 *      status        PKIStatus,
31 *      statusString  PKIFreeText     OPTIONAL,
32 *      failInfo      PKIFailureInfo  OPTIONAL
33 * }
34 *</pre>
35 *
36 * <pre>
37 * PKIStatus ::= INTEGER {
38 *      accepted               (0),
39 *      grantedWithMods        (1),
40 *      rejection              (2),
41 *      waiting                (3),
42 *      revocationWarning      (4),
43 *      revocationNotification (5),
44 *      keyUpdateWarning       (6)
45 * }
46 * </pre>
47 *
48 * <pre>
49 * PKIFailureInfo ::= BIT STRING {
50 *      badAlg              (0),
51 *      badMessageCheck     (1),
52 *      badRequest          (2),
53 *      badTime             (3),
54 *      badCertId           (4),
55 *      badDataFormat       (5),
56 *      wrongAuthority      (6),
57 *      incorrectData       (7),
58 *      missingTimeStamp    (8),
59 *      badPOP              (9),
60 *      certRevoked         (10),
61 *      certConfirmed       (11),
62 *      wrongIntegrity      (12),
63 *      badRecipientNonce   (13),
64 *      timeNotAvailable    (14),
65 *      unacceptedPolicy    (15),
66 *      unacceptedExtension (16),
67 *      addInfoNotAvailable (17),
68 *      badSenderNonce      (18),
69 *      badCertTemplate     (19),
70 *      signerNotTrusted    (20),
71 *      transactionIdInUse  (21),
72 *      unsupportedVersion  (22),
73 *      notAuthorized       (23),
74 *      systemUnavail       (24),
75 *      systemFailure       (25),
76 *      duplicateCertReq    (26),
77 *      extendLater        (100), -- GuardTime specific extension
78 *      extensionOverdue   (101)  -- GuardTime specific extension
79 * }
80 * </pre>
81 *
82 * <pre>
83 * PKIFreeText ::= SEQUENCE SIZE (1..MAX) OF UTF8String
84 * </pre>
85 *
86 * @package asn1
87 * @subpackage cmp
88 *
89 * @link http://tools.ietf.org/html/rfc4210#section-5.2.3 RFC 4210: Certificate Management Protocol
90 */
91class PKIStatusInfo {
92
93    private $status;
94    private $statusString;
95    private $failInfo;
96
97    /**
98     * Constructs a new instance of PKIStatusInfo.
99     */
100    public function __construct() {
101    }
102
103    /**
104     * Decodes an ASN1Sequence as PKIStatusInfo.
105     *
106     * @throws GTException
107     * @param  ASN1Sequence $object PKIStatusInfo encoded as an ASN1Sequence
108     * @return void
109     */
110    public function decode($object) {
111
112        if (!$object instanceof ASN1Sequence) {
113            throw new GTException("Expecting an ASN1Sequence");
114        }
115
116        $this->status = (int) $object->getObjectAt(0)->getValue();
117
118        for ($i = 1; $i < $object->getObjectCount(); $i++) {
119
120            $item = $object->getObjectAt($i);
121
122            if ($item instanceof ASN1BitString) {
123                $this->failInfo = $item->getValue();
124
125            } else if ($item instanceof ASN1Sequence) {
126
127                $statusString = array();
128
129                foreach ($item->getObjects() as $line) {
130                    array_push($statusString, $line->getValue());
131                }
132
133                $this->statusString = $statusString;
134
135            } else {
136
137                throw new GTException("Unexpected item: " . get_class($item));
138            }
139        }
140    }
141
142    /**
143     * Gets the status code.
144     *
145     * @return int status code
146     */
147    public function getStatus() {
148        return $this->status;
149    }
150
151    /**
152     * Sets the status code.
153     *
154     * @param  int $status
155     * @return void
156     */
157    public function setStatus($status) {
158        $this->status = $status;
159    }
160
161    /**
162     * Gets the status message.
163     *
164     * @return string status message
165     */
166    public function getStatusMessage() {
167
168        if (!empty($this->statusString)) {
169            return implode("\n", $this->statusString);
170        }
171
172        return "";
173
174    }
175
176    /**
177     * Gets the failure info bit string.
178     *
179     * @return string failure info bit string
180     */
181    public function getFailInfo() {
182        return $this->failInfo;
183    }
184}
185
186?>
187