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 tsp
22 */
23
24/**
25 * Represents the timestamp verification result.
26 *
27 * @package tsp
28 */
29class GTVerificationResult extends GTVerifificationResultBase {
30
31    /******************************************* STATUS CODES *******************************************/
32
33    /**
34     * Short-term RSA signature was present in the timestamp.
35     *
36     * @see getStatusCode, hasStatus
37     */
38    const PUBLIC_KEY_SIGNATURE_PRESENT = 1;
39
40    /**
41     * Long-term publication reference was present in the timestamp.
42     *
43     * @see getStatusCode, hasStatus
44     */
45    const PUBLICATION_REFERENCE_PRESENT = 2;
46
47    /**
48     * Timestamp was checked against the data hash.
49     *
50     * @see getStatusCode, hasStatus
51     */
52    const DATA_HASH_CHECKED = 16;
53
54    /**
55     * Timestamp was checked against control publication.
56     *
57     * @see getStatusCode, hasStatus
58     */
59    const PUBLICATION_CHECKED = 32;
60
61    /**
62     * Publications file signature was verified.
63     *
64     * @see getStatusCode, hasStatus
65     */
66    const PUBFILE_SIGNATURE_VERIFIED = 64;
67
68    /******************************************* ERROR CODES *******************************************/
69
70    /**
71     * Timestamp has invalid syntax.
72     *
73     * @see getErrorCode, hasError
74     */
75    const SYNTACTIC_CHECK_FAILURE = 1;
76
77    /**
78     * Hash chain computation result does not match the publication imprint.
79     *
80     * @see getErrorCode, hasError
81     */
82    const HASHCHAIN_VERIFICATION_FAILURE = 2;
83
84    /**
85     * Signed data structure is incorrectly composed, i.e. wrong data is signed
86     * or the signature does not match the public key in the timestamp.
87     *
88     * @see getErrorCode, hasError
89     */
90    const PUBLIC_KEY_SIGNATURE_FAILURE = 16;
91
92    /**
93     * Public key of signed timestamp is not found among published ones.
94     *
95     * @see getErrorCode, hasError
96     */
97    const PUBLIC_KEY_FAILURE = 64;
98
99    /**
100     * Timestamp does not match with the document it is claimed to belong to.
101     *
102     * @see getErrorCode, hasError
103     */
104    const WRONG_DOCUMENT_FAILURE = 128;
105
106    /**
107     * Publications file is inconsistent with the corresponding data in
108     * timestamp -- publication identifiers or published hash values do not
109     * match.
110     *
111     * @see getErrorCode, hasError
112     */
113    const PUBLICATION_FAILURE = 256;
114
115    /**
116     * Signed data certificate validation failed.
117     *
118     * @see getErrorCode, hasError
119     */
120    const CERTIFICATE_FAILURE = 512;
121
122    /**
123     * Technical failure occurred while verifying timestamp.
124     *
125     * @see getErrorCode, hasError
126     */
127    const TECH_FAILURE = 1024;
128
129    /**
130     * Publications file signature failure.
131     *
132     * @see getErrorCode, hasError
133     */
134    const PUBFILE_SIGNATURE_FAILURE = 2048;
135
136    private $cainfo;
137
138    /**
139     * Updates this verification result with status/error bitfields from specified verification result.
140     *
141     * @param  GTVerificationResultBase $other other verification result
142     * @return void
143     */
144    public function update(GTVerifificationResultBase $other) {
145        $this->updateStatus($other->getStatusCode());
146        $this->updateErrors($other->getErrorCode());
147    }
148
149    /**
150     * Sets the root certificates path used for verification.
151     *
152     * @param  string|array $cainfo root certificates path
153     * @return void
154     *
155     * @see openssl_verify
156     */
157    public function setCainfo($cainfo) {
158        $this->cainfo = $cainfo;
159    }
160
161    /**
162     * Gets the root certificates path used for verification.
163     *
164     * @return string|array root certificates path
165     *
166     * @see openssl_verify
167     */
168    public function getCainfo() {
169        return $this->cainfo;
170    }
171}
172
173?>
174