<?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 asn1
 * @subpackage tsp
 */

/**
 * TSP TimeStampReq implementation.
 *
 * <pre>
 * TimeStampReq ::= SEQUENCE  {
 *  version                  INTEGER  { v1(1) },
 *  messageImprint           MessageImprint,
 *  reqPolicy                TSAPolicyId                OPTIONAL,
 *  nonce                    INTEGER                    OPTIONAL,
 *  certReq                  BOOLEAN                    DEFAULT FALSE,
 *  extensions               [0] IMPLICIT Extensions    OPTIONAL
 * }
 * </pre>
 *
 * @see TSPMessageImprint
 *
 * @package asn1
 * @subpackage tsp
 *
 * @link http://tools.ietf.org/html/rfc3161#section-2.4.1 RFC 3161: Time-Stamp Protocol
 */
class TSPTimeStampReq implements ASN1DEREncodable {

    const VERSION = 1;

    private $version;
    private $messageImprint;

    /**
     * Constructs a new instance of TSPTimeStampReq.
     */
    public function __construct() {
        $this->version = self::VERSION;
    }

    /**
     * Encodes this TSPTimestampReq using DER.
     *
     * @return array byte array that contains the DER encoding of this TSPTimestampReq
     */
    public function encodeDER() {

        $sequence = new ASN1Sequence();

        $sequence->add(new ASN1Integer($this->version));
        $sequence->add($this->messageImprint);

        return $sequence->encodeDER();
    }

    /**
     * Gets the version.
     *
     * @return int version
     */
    public function getVersion() {
        return $this->version;
    }

    /**
     * Sets the message imprint.
     *
     * @throws GTException
     * @param  TSPMessageImprint $messageImprint the message imprint
     * @return void
     */
    public function setMessageImprint($messageImprint) {

        if (!$messageImprint instanceof TSPMessageImprint) {
            throw new GTException("messageImprint must be an instance of TSPMessageImprint");
        }

        $this->messageImprint = $messageImprint;

    }

    /**
     * Gets the message imprint.
     *
     * @return TSPMessageImprint the message imprint
     */
    public function getMessageImprint() {
        return $this->messageImprint;
    }

}

?>
