001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 *
019 */
020package org.apache.directory.shared.kerberos.codec;
021
022
023import org.apache.directory.api.asn1.ber.grammar.Grammar;
024import org.apache.directory.api.asn1.ber.grammar.States;
025
026
027/**
028 * This class store the Kerberos grammar's constants. It is also used for debugging
029 * purpose. We will decode all the Kerberos messages :
030 * <ul>
031 * <li>0x6A : AS-REQ</li>
032 * <li>0x6B : AS-REP</li>
033 * <li>0x6C : TGS-REQ</li>
034 * <li>0x6D : TGS-REP</li>
035 * <li>0x6E : AP-REQ</li>
036 * <li>0x6F : AP-REP</li>
037 * <li>0x74 : KRB-SAFE</li>
038 * <li>0x75 : KRB-PRIV</li>
039 * <li>0x76 : KRB-CRED</li>
040 * <li>0x7E : KRB-ERROR</li>
041 * </ul>
042 *
043 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
044 */
045public enum KerberosMessageStatesEnum implements States
046{
047    // Start
048    START_STATE,
049
050    // ----- Kerberos message --------------------------------------------
051
052    AS_REQ_STATE, // 0x6A
053    AS_REP_TAG_STATE, // 0x6B
054    TGS_REQ_TAG_STATE, // 0x6C
055    TGS_REP_TAG_STATE, // 0x6D
056    AP_REQ_TAG_STATE, // 0x6E
057    AP_REP_TAG_STATE, // 0x6F
058    KRB_SAFE_STATE, // 0x74
059    KRB_PRIV_STATE, // 0x75
060    KRB_CRED_STATE, // 0x76
061    KRB_ERROR_STATE, // 0x7E
062
063    // End
064    LAST_KERBEROS_MESSAGE_STATE;
065
066    /**
067     * Get the grammar name
068     *
069     * @param grammar The grammar code
070     * @return The grammar name
071     */
072    public String getGrammarName( int grammar )
073    {
074        return "KERBEROS_MESSAGE_GRAMMAR";
075    }
076
077
078    /**
079     * Get the grammar name
080     *
081     * @param grammar The grammar class
082     * @return The grammar name
083     */
084    public String getGrammarName( Grammar<KerberosMessageContainer> grammar )
085    {
086        if ( grammar instanceof KerberosMessageGrammar )
087        {
088            return "KERBEROS_MESSAGE_GRAMMAR";
089        }
090        else
091        {
092            return "UNKNOWN GRAMMAR";
093        }
094    }
095
096
097    /**
098     * Get the string representing the state
099     *
100     * @param state The state number
101     * @return The String representing the state
102     */
103    public String getState( int state )
104    {
105        return ( ( state == LAST_KERBEROS_MESSAGE_STATE.ordinal() ) ? "KERBEROS_MESSAGE_END_STATE" : name() );
106    }
107
108
109    /**
110     * {@inheritDoc}
111     */
112    public boolean isEndState()
113    {
114        return this == LAST_KERBEROS_MESSAGE_STATE;
115    }
116
117
118    /**
119     * {@inheritDoc}
120     */
121    public KerberosMessageStatesEnum getStartState()
122    {
123        return START_STATE;
124    }
125}