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.encApRepPart;
021
022
023import org.apache.directory.api.asn1.actions.CheckNotNullLength;
024import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
025import org.apache.directory.api.asn1.ber.grammar.Grammar;
026import org.apache.directory.api.asn1.ber.grammar.GrammarTransition;
027import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
028import org.apache.directory.shared.kerberos.KerberosConstants;
029import org.apache.directory.shared.kerberos.codec.encApRepPart.actions.EncApRepPartInit;
030import org.apache.directory.shared.kerberos.codec.encApRepPart.actions.StoreCTime;
031import org.apache.directory.shared.kerberos.codec.encApRepPart.actions.StoreCusec;
032import org.apache.directory.shared.kerberos.codec.encApRepPart.actions.StoreSeqNumber;
033import org.apache.directory.shared.kerberos.codec.encApRepPart.actions.StoreSubKey;
034import org.slf4j.Logger;
035import org.slf4j.LoggerFactory;
036
037
038/**
039 * This class implements the EncApRepPart structure. All the actions are declared
040 * in this class. As it is a singleton, these declaration are only done once. If
041 * an action is to be added or modified, this is where the work is to be done !
042 *
043 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
044 */
045public final class EncApRepPartGrammar extends AbstractGrammar<EncApRepPartContainer>
046{
047    /** The logger */
048    static final Logger LOG = LoggerFactory.getLogger( EncApRepPartGrammar.class );
049
050    /** A speedup for logger */
051    static final boolean IS_DEBUG = LOG.isDebugEnabled();
052
053    /** The instance of grammar. EncApRepPartGrammar is a singleton */
054    private static Grammar<EncApRepPartContainer> instance = new EncApRepPartGrammar();
055
056
057    /**
058     * Creates a new EncApRepPartGrammar object.
059     */
060    @SuppressWarnings("unchecked")
061    private EncApRepPartGrammar()
062    {
063        setName( EncApRepPartGrammar.class.getName() );
064
065        // Create the transitions table
066        super.transitions = new GrammarTransition[EncApRepPartStatesEnum.LAST_ENC_AP_REP_PART_STATE.ordinal()][256];
067
068        // ============================================================================================
069        // EncApRepPart
070        // ============================================================================================
071        // --------------------------------------------------------------------------------------------
072        // Transition from EncApRepPart init to APPLICATION tag
073        // --------------------------------------------------------------------------------------------
074        // EncAPRepPart    ::= [APPLICATION 27]
075        super.transitions[EncApRepPartStatesEnum.START_STATE.ordinal()][KerberosConstants.ENC_AP_REP_PART_TAG] =
076            new GrammarTransition<EncApRepPartContainer>(
077                EncApRepPartStatesEnum.START_STATE,
078                EncApRepPartStatesEnum.ENC_AP_REP_PART_STATE,
079                KerberosConstants.ENC_AP_REP_PART_TAG,
080                new EncApRepPartInit() );
081
082        // --------------------------------------------------------------------------------------------
083        // Transition from EncApRepPart APPLICATION to EncApRepPart SEQ
084        // --------------------------------------------------------------------------------------------
085        // EncAPRepPart    ::= [APPLICATION 27] SEQUENCE {
086        super.transitions[EncApRepPartStatesEnum.ENC_AP_REP_PART_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
087            new GrammarTransition<EncApRepPartContainer>(
088                EncApRepPartStatesEnum.ENC_AP_REP_PART_STATE,
089                EncApRepPartStatesEnum.ENC_AP_REP_PART_SEQ_STATE,
090                UniversalTag.SEQUENCE,
091                new CheckNotNullLength<EncApRepPartContainer>() );
092
093        // --------------------------------------------------------------------------------------------
094        // Transition from EncApRepPart SEQ to ctime tag
095        // --------------------------------------------------------------------------------------------
096        // EncAPRepPart    ::= [APPLICATION 27] SEQUENCE {
097        //         ctime           [0]
098        super.transitions[EncApRepPartStatesEnum.ENC_AP_REP_PART_SEQ_STATE.ordinal()][KerberosConstants.ENC_AP_REP_PART_CTIME_TAG] =
099            new GrammarTransition<EncApRepPartContainer>(
100                EncApRepPartStatesEnum.ENC_AP_REP_PART_SEQ_STATE,
101                EncApRepPartStatesEnum.ENC_AP_REP_PART_CTIME_TAG_STATE,
102                KerberosConstants.ENC_AP_REP_PART_CTIME_TAG,
103                new CheckNotNullLength<EncApRepPartContainer>() );
104
105        // --------------------------------------------------------------------------------------------
106        // Transition from ctime tag to ctime value
107        // --------------------------------------------------------------------------------------------
108        // EncAPRepPart    ::= [APPLICATION 27] SEQUENCE {
109        //         ctime           [0] KerberosTime,
110        super.transitions[EncApRepPartStatesEnum.ENC_AP_REP_PART_CTIME_TAG_STATE.ordinal()][UniversalTag.GENERALIZED_TIME
111            .getValue()] =
112            new GrammarTransition<EncApRepPartContainer>(
113                EncApRepPartStatesEnum.ENC_AP_REP_PART_CTIME_TAG_STATE,
114                EncApRepPartStatesEnum.ENC_AP_REP_PART_CTIME_STATE,
115                UniversalTag.GENERALIZED_TIME,
116                new StoreCTime() );
117
118        // --------------------------------------------------------------------------------------------
119        // Transition from ctime value to cusec tag
120        // --------------------------------------------------------------------------------------------
121        // EncAPRepPart    ::= [APPLICATION 27] SEQUENCE {
122        //         ...
123        //         cusec           [1]
124        super.transitions[EncApRepPartStatesEnum.ENC_AP_REP_PART_CTIME_STATE.ordinal()][KerberosConstants.ENC_AP_REP_PART_CUSEC_TAG] =
125            new GrammarTransition<EncApRepPartContainer>(
126                EncApRepPartStatesEnum.ENC_AP_REP_PART_CTIME_STATE,
127                EncApRepPartStatesEnum.ENC_AP_REP_PART_CUSEC_TAG_STATE,
128                KerberosConstants.ENC_AP_REP_PART_CUSEC_TAG,
129                new CheckNotNullLength<EncApRepPartContainer>() );
130
131        // --------------------------------------------------------------------------------------------
132        // Transition from cusec tag to cusec value
133        // --------------------------------------------------------------------------------------------
134        // EncAPRepPart    ::= [APPLICATION 27] SEQUENCE {
135        //         ...
136        //         cusec           [1] Microseconds,
137        super.transitions[EncApRepPartStatesEnum.ENC_AP_REP_PART_CUSEC_TAG_STATE.ordinal()][UniversalTag.INTEGER
138            .getValue()] =
139            new GrammarTransition<EncApRepPartContainer>(
140                EncApRepPartStatesEnum.ENC_AP_REP_PART_CUSEC_TAG_STATE,
141                EncApRepPartStatesEnum.ENC_AP_REP_PART_CUSEC_STATE,
142                UniversalTag.INTEGER,
143                new StoreCusec() );
144
145        // --------------------------------------------------------------------------------------------
146        // Transition from cusec value to subkey
147        // --------------------------------------------------------------------------------------------
148        // EncAPRepPart    ::= [APPLICATION 27] SEQUENCE {
149        //         ...
150        //         subkey          [2] <EncryptionKey> OPTIONAL,
151        super.transitions[EncApRepPartStatesEnum.ENC_AP_REP_PART_CUSEC_STATE.ordinal()][KerberosConstants.ENC_AP_REP_PART_SUB_KEY_TAG] =
152            new GrammarTransition<EncApRepPartContainer>(
153                EncApRepPartStatesEnum.ENC_AP_REP_PART_CUSEC_STATE,
154                EncApRepPartStatesEnum.ENC_AP_REP_PART_SUBKEY_STATE,
155                KerberosConstants.ENC_AP_REP_PART_SUB_KEY_TAG,
156                new StoreSubKey() );
157
158        // --------------------------------------------------------------------------------------------
159        // Transition from cusec value to seq-number tag
160        // --------------------------------------------------------------------------------------------
161        // EncAPRepPart    ::= [APPLICATION 27] SEQUENCE {
162        //         ...
163        //         seq-number      [3] UInt32 OPTIONAL
164        super.transitions[EncApRepPartStatesEnum.ENC_AP_REP_PART_CUSEC_STATE.ordinal()][KerberosConstants.ENC_AP_REP_PART_SEQ_NUMBER_TAG] =
165            new GrammarTransition<EncApRepPartContainer>(
166                EncApRepPartStatesEnum.ENC_AP_REP_PART_CUSEC_STATE,
167                EncApRepPartStatesEnum.ENC_AP_REP_PART_SEQ_NUMBER_TAG_STATE,
168                KerberosConstants.ENC_AP_REP_PART_SEQ_NUMBER_TAG,
169                new CheckNotNullLength<EncApRepPartContainer>() );
170
171        // --------------------------------------------------------------------------------------------
172        // Transition from subkey to seq-number tag
173        // --------------------------------------------------------------------------------------------
174        // EncAPRepPart    ::= [APPLICATION 27] SEQUENCE {
175        //         ...
176        //         seq-number      [3] UInt32 OPTIONAL
177        super.transitions[EncApRepPartStatesEnum.ENC_AP_REP_PART_SUBKEY_STATE.ordinal()][KerberosConstants.ENC_AP_REP_PART_SEQ_NUMBER_TAG] =
178            new GrammarTransition<EncApRepPartContainer>(
179                EncApRepPartStatesEnum.ENC_AP_REP_PART_SUBKEY_STATE,
180                EncApRepPartStatesEnum.ENC_AP_REP_PART_SEQ_NUMBER_TAG_STATE,
181                KerberosConstants.ENC_AP_REP_PART_SEQ_NUMBER_TAG,
182                new CheckNotNullLength<EncApRepPartContainer>() );
183
184        // --------------------------------------------------------------------------------------------
185        // Transition from seq-number tag to seq-number value
186        // --------------------------------------------------------------------------------------------
187        // EncAPRepPart    ::= [APPLICATION 27] SEQUENCE {
188        //         ...
189        //         seq-number      [3] UInt32 OPTIONAL
190        // }
191        super.transitions[EncApRepPartStatesEnum.ENC_AP_REP_PART_SEQ_NUMBER_TAG_STATE.ordinal()][UniversalTag.INTEGER
192            .getValue()] =
193            new GrammarTransition<EncApRepPartContainer>(
194                EncApRepPartStatesEnum.ENC_AP_REP_PART_SEQ_NUMBER_TAG_STATE,
195                EncApRepPartStatesEnum.ENC_AP_REP_PART_SEQ_NUMBER_STATE,
196                UniversalTag.INTEGER,
197                new StoreSeqNumber() );
198    }
199
200
201    /**
202     * Get the instance of this grammar
203     *
204     * @return An instance on the EncApRepPart Grammar
205     */
206    public static Grammar<EncApRepPartContainer> getInstance()
207    {
208        return instance;
209    }
210}