// Copyright 1997 The Open Group Research Institute.  All rights reserved.

package krb5.lib;

import krb5.lib.asn1.*;
import java.util.Vector;

/**
 * Last request
 */
public class LastReq {

	/**
	 * Last request entry
	 */
	public LastReqEntry[] entry;

	/**
	 * Class constructor
	 *
	 * @param ref is of type EncodeRef
	 * @exception Asn1Exception an exception
	 * @see krb5.lib.asn1.EncodeRef
	 * @see krb5.lib.Asn1Exception
	 */
	public LastReq(EncodeRef ref) throws Asn1Exception {
		Vector tempEntry = new Vector();
		EncodeRef subRef = decode.Sequence(ref);
		while (subRef.isMoreInSequence()) {
			tempEntry.addElement(new LastReqEntry(subRef));
			subRef.next();
		}
		if (tempEntry.size() > 0) {
			entry = new LastReqEntry[tempEntry.size()];
			tempEntry.copyInto(entry);
		}
	}

	/**
	 * Encodes the object in asn1
	 *
	 * @return byte[] is a result
	 * @exception Asn1Exception an exception
	 * @see krb5.lib.Asn1Exception
	 */
	public byte[] asn1Encode() throws Asn1Exception {
		byte[][] last_req = null;
		if (entry != null && entry.length > 0) {
			last_req = new byte[entry.length][];
			for (int i = 0; i < entry.length; i++)
				last_req[i] = entry[i].asn1Encode();
		}
		return encode.Sequence(last_req);
	}

}