// Copyright 1997 The Open Group Research Institute.  All rights reserved.
/**
 * AuthorizationData 
 */

package krb5.lib;

import krb5.lib.asn1.*;
import java.util.Vector;

public class AuthorizationData implements Cloneable {

    /**
     * array of authorization data entry
     */
	public AuthorizationDataEntry[] entry;

    /**
     * Class constructor
     */
	private AuthorizationData() {
	}

	/**
	 * Class constructor specifying an array of data entries.
	 *
	 * @param new_entries is of type AuthorizationDataEntry[]
	 * @see krb5.lib.AuthorizationDataEntry
	 */
	public AuthorizationData(
		AuthorizationDataEntry[] new_entries
	) {
		entry = new_entries;
	}

	/**
	 * Class constructor specifying AuthroizationDataEntry.
	 *
	 * @param new_entry is of type AuthorizationDataEntry
	 * @see krb5.lib.AuthorizationDataEntry
	 */
	public AuthorizationData(
		AuthorizationDataEntry new_entry
	) {
		entry = new AuthorizationDataEntry[1];
		entry[0] = new_entry;
	}

	/**
	 * Clones a copy of the object.
	 *
	 * @return Object is a result
	 */
	public Object clone() {
		AuthorizationData new_authorizationData =
			new AuthorizationData();
		if (entry != null) {
			new_authorizationData.entry =
				new AuthorizationDataEntry[entry.length];
			for (int i = 0; i < entry.length; i++)
				new_authorizationData.entry[i] =
					(AuthorizationDataEntry)entry[i].clone();
		}
		return new_authorizationData;
	}

	/**
	 * Class constructor specifying an encoded reference.
	 *
	 * @param ref is of type EncodeRef
	 * @exception Asn1Exception an exception
	 * @see krb5.lib.asn1.EncodeRef
	 * @see krb5.lib.Asn1Exception
	 */
	public AuthorizationData(EncodeRef ref) throws Asn1Exception {
		Vector tempEntry = new Vector();
		EncodeRef subRef = decode.Sequence(ref);
		while (subRef.isMoreInSequence()) {
			tempEntry.addElement(new AuthorizationDataEntry(subRef));
			subRef.next();
		}
		if (tempEntry.size() > 0) {
			entry = new AuthorizationDataEntry[tempEntry.size()];
			tempEntry.copyInto(entry);
		}
	}

	/**
	 * Encodes the object in asn1
	 *
	 * @return byte[] is a result in array of bytes
	 * @exception Asn1Exception an exception
	 * @see krb5.lib.Asn1Exception
	 */
	public byte[] asn1Encode() throws Asn1Exception {
		byte[][] authorization_data = null;
		if (entry != null && entry.length > 0) {
			authorization_data = new byte[entry.length][];
			for (int i = 0; i < entry.length; i++)
				authorization_data[i] = entry[i].asn1Encode();
		}
		return encode.Sequence(authorization_data);
	}

}

