// Copyright 1997 The Open Group Research Institute.  All rights reserved.

package krb5.lib;

import krb5.lib.asn1.*;

/**
 * Flags for the ticket
 */
public class TicketFlags extends BitString {

	/**
	 * Class constructor
	 */
	public TicketFlags() {
		super(Krb5.TKT_OPTS_MAX + 1);
	}

	/**
	 * Class constructor
	 *
	 * @param data is of type byte[]
	 * @param size is of type int
	 * @exception BitStringException an exception
	 * @see krb5.lib.BitStringException
	 */
	public TicketFlags(byte[] data, int size) throws BitStringException {
		super(data, size);
		if (size != Krb5.TKT_OPTS_MAX + 1)
			throw new BitStringException(Krb5.BITSTRING_BAD_LENGTH);
	}

	/**
	 * Class constructor
	 *
	 * @param ref is of type EncodeRef
	 * @exception Asn1Exception an exception
	 * @exception BitStringException an exception
	 * @see krb5.lib.asn1.EncodeRef
	 * @see krb5.lib.Asn1Exception
	 * @see krb5.lib.BitStringException
	 */
	public TicketFlags(EncodeRef ref) throws Asn1Exception,
		BitStringException {
		super(ref);
		if (size() != Krb5.TKT_OPTS_MAX + 1)
			throw new BitStringException(Krb5.BITSTRING_BAD_LENGTH);
	}

	/**
	 * Clones a copy of the object
	 *
	 * @return Object is a result
	 */
	public Object clone() {
	    return super.clone();
	}

	/**
	 * Converts the object to a printable string
	 *
	 * @return String is a result
	 */
	public String toString() {
	    StringBuffer result = new StringBuffer();
	    try {
	        if (get(Krb5.TKT_OPTS_FORWARDABLE))
	            result.append("FORWARDABLE ");
	        if (get(Krb5.TKT_OPTS_FORWARDED))
	            result.append("FORWARDED ");
	        if (get(Krb5.TKT_OPTS_PROXIABLE))
	            result.append("PROXIABLE ");
	        if (get(Krb5.TKT_OPTS_PROXY))
	            result.append("PROXY ");
	        if (get(Krb5.TKT_OPTS_MAY_POSTDATE))
	            result.append("MAY_POSTDATE ");
	        if (get(Krb5.TKT_OPTS_POSTDATED))
	            result.append("POSTDATED ");
	        if (get(Krb5.TKT_OPTS_INVALID))
	            result.append("INVALID ");
	        if (get(Krb5.TKT_OPTS_RENEWABLE))
	            result.append("RENEWABLE ");
	        if (get(Krb5.TKT_OPTS_INITIAL))
	            result.append("INITIAL ");
	        if (get(Krb5.TKT_OPTS_PRE_AUTHENT))
	            result.append("PRE_AUTHENT ");
	        if (get(Krb5.TKT_OPTS_HW_AUTHENT))
	            result.append("HW_AUTHENT ");
	        if (get(Krb5.TKT_OPTS_TRANSITED_POLICY_CHECKED))
	            result.append("TRANSITED_POLICY_CHECKED ");
	        if (get(Krb5.TKT_OPTS_OK_AS_DELEGATE))
	            result.append("OPTS_OK_AS_DELEGATE ");
	    } catch (BitStringException e) {};
	    if (result.length() > 0 && result.charAt(result.length()) == ' ')
	        result.setLength(result.length() - 1);
	    return result.toString();
	}
}