<?php
/*
 * Copyright 2008-2010 GuardTime AS
 *
 * This file is part of the GuardTime PHP SDK.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @package tsp
 */

/**
 * Represents the timestamp verification result.
 *
 * @package tsp
 */
class GTVerificationResult extends GTVerifificationResultBase {

    /******************************************* STATUS CODES *******************************************/

    /**
     * Short-term RSA signature was present in the timestamp.
     *
     * @see getStatusCode, hasStatus
     */
    const PUBLIC_KEY_SIGNATURE_PRESENT = 1;

    /**
     * Long-term publication reference was present in the timestamp.
     *
     * @see getStatusCode, hasStatus
     */
    const PUBLICATION_REFERENCE_PRESENT = 2;

    /**
     * Timestamp was checked against the data hash.
     *
     * @see getStatusCode, hasStatus
     */
    const DATA_HASH_CHECKED = 16;

    /**
     * Timestamp was checked against control publication.
     *
     * @see getStatusCode, hasStatus
     */
    const PUBLICATION_CHECKED = 32;

    /**
     * Publications file signature was verified.
     *
     * @see getStatusCode, hasStatus
     */
    const PUBFILE_SIGNATURE_VERIFIED = 64;

    /******************************************* ERROR CODES *******************************************/

    /**
     * Timestamp has invalid syntax.
     *
     * @see getErrorCode, hasError
     */
    const SYNTACTIC_CHECK_FAILURE = 1;

    /**
     * Hash chain computation result does not match the publication imprint.
     *
     * @see getErrorCode, hasError
     */
    const HASHCHAIN_VERIFICATION_FAILURE = 2;

    /**
     * Signed data structure is incorrectly composed, i.e. wrong data is signed
     * or the signature does not match the public key in the timestamp.
     *
     * @see getErrorCode, hasError
     */
    const PUBLIC_KEY_SIGNATURE_FAILURE = 16;

    /**
     * Public key of signed timestamp is not found among published ones.
     *
     * @see getErrorCode, hasError
     */
    const PUBLIC_KEY_FAILURE = 64;

    /**
     * Timestamp does not match with the document it is claimed to belong to.
     *
     * @see getErrorCode, hasError
     */
    const WRONG_DOCUMENT_FAILURE = 128;

    /**
     * Publications file is inconsistent with the corresponding data in
     * timestamp -- publication identifiers or published hash values do not
     * match.
     *
     * @see getErrorCode, hasError
     */
    const PUBLICATION_FAILURE = 256;

    /**
     * Signed data certificate validation failed.
     *
     * @see getErrorCode, hasError
     */
    const CERTIFICATE_FAILURE = 512;

    /**
     * Technical failure occurred while verifying timestamp.
     *
     * @see getErrorCode, hasError
     */
    const TECH_FAILURE = 1024;

    /**
     * Publications file signature failure.
     *
     * @see getErrorCode, hasError
     */
    const PUBFILE_SIGNATURE_FAILURE = 2048;

    private $cainfo;

    /**
     * Updates this verification result with status/error bitfields from specified verification result.
     *
     * @param  GTVerificationResultBase $other other verification result
     * @return void
     */
    public function update(GTVerifificationResultBase $other) {
        $this->updateStatus($other->getStatusCode());
        $this->updateErrors($other->getErrorCode());
    }

    /**
     * Sets the root certificates path used for verification.
     *
     * @param  string|array $cainfo root certificates path
     * @return void
     *
     * @see openssl_verify
     */
    public function setCainfo($cainfo) {
        $this->cainfo = $cainfo;
    }

    /**
     * Gets the root certificates path used for verification.
     *
     * @return string|array root certificates path
     *
     * @see openssl_verify
     */
    public function getCainfo() {
        return $this->cainfo;
    }
}

?>
