<?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
 */

/**
 * ASN.1 Null implementation.
 *
 * @package asn1
 */
class ASN1Null extends ASN1Object {

    /**
     * Constructs a new instance of ASN1Null.
     * @return void
     */
    public function __construct() {
    }

    /**
     * Encodes ASN1Null as DER byte array.
     *
     * @return array DER encoding of this ASN1Null
     */
    public function encodeDER() {

        $bytes = array();

        $this->append($bytes, ASN1DER::encodeType(ASN1_TAG_NULL));
        $this->append($bytes, 0x0);

        return $bytes;
    }

    /**
     * Decodes an ASN1Null object.
     *
     * For ASN1Null the byte stream must be empty (no V bytes, just TL)
     *
     * @throws GTException
     * @param  array $bytes null or empty array
     * @return void
     */
    public function decodeDER($bytes) {

        if (!empty($bytes)) {
            throw new GTException("ASN1Null TLV should not contain any V bytes");
        }
    }
}

?>
