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.paEncTsEnc;
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.paEncTsEnc.actions.PaEncTsEncInit;
030import org.apache.directory.shared.kerberos.codec.paEncTsEnc.actions.StorePaTimestamp;
031import org.apache.directory.shared.kerberos.codec.paEncTsEnc.actions.StorePaUsec;
032import org.slf4j.Logger;
033import org.slf4j.LoggerFactory;
034
035
036/**
037 * This class implements the PaEncTsEnc structure. All the actions are declared
038 * in this class. As it is a singleton, these declaration are only done once. If
039 * an action is to be added or modified, this is where the work is to be done !
040 *
041 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
042 */
043public final class PaEncTsEncGrammar extends AbstractGrammar<PaEncTsEncContainer>
044{
045    /** The logger */
046    static final Logger LOG = LoggerFactory.getLogger( PaEncTsEncGrammar.class );
047
048    /** A speedup for logger */
049    static final boolean IS_DEBUG = LOG.isDebugEnabled();
050
051    /** The instance of grammar. PaEncTsEncGrammar is a singleton */
052    private static Grammar<PaEncTsEncContainer> instance = new PaEncTsEncGrammar();
053
054
055    /**
056     * Creates a new PaEncTsEncrGrammar object.
057     */
058    @SuppressWarnings("unchecked")
059    private PaEncTsEncGrammar()
060    {
061        setName( PaEncTsEncGrammar.class.getName() );
062
063        // Create the transitions table
064        super.transitions = new GrammarTransition[PaEncTsEncStatesEnum.LAST_PA_ENC_TS_ENC_STATE.ordinal()][256];
065
066        // ============================================================================================
067        // PaEncTsEnc
068        // ============================================================================================
069        // --------------------------------------------------------------------------------------------
070        // Transition from PaEncTsEnc init to PaEncTsEnc SEQ
071        // --------------------------------------------------------------------------------------------
072        // PA-ENC-TS-ENC           ::= SEQUENCE {
073        super.transitions[PaEncTsEncStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
074            new GrammarTransition<PaEncTsEncContainer>(
075                PaEncTsEncStatesEnum.START_STATE,
076                PaEncTsEncStatesEnum.PA_ENC_TS_ENC_STATE,
077                UniversalTag.SEQUENCE,
078                new PaEncTsEncInit() );
079
080        // --------------------------------------------------------------------------------------------
081        // Transition from PaEncTsEnc SEQ to patimestamp tag
082        // --------------------------------------------------------------------------------------------
083        // PA-ENC-TS-ENC           ::= SEQUENCE {
084        //         patimestamp     [0]
085        super.transitions[PaEncTsEncStatesEnum.PA_ENC_TS_ENC_STATE.ordinal()][KerberosConstants.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG] =
086            new GrammarTransition<PaEncTsEncContainer>(
087                PaEncTsEncStatesEnum.PA_ENC_TS_ENC_STATE,
088                PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG_STATE,
089                KerberosConstants.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG,
090                new CheckNotNullLength<PaEncTsEncContainer>() );
091
092        // --------------------------------------------------------------------------------------------
093        // Transition from patimestamp tag to patimestamp  value
094        // --------------------------------------------------------------------------------------------
095        // PA-ENC-TS-ENC           ::= SEQUENCE {
096        //         patimestamp     [0] KerberosTime -- client's time --,
097        super.transitions[PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG_STATE.ordinal()][UniversalTag.GENERALIZED_TIME
098            .getValue()] =
099            new GrammarTransition<PaEncTsEncContainer>(
100                PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_TIMESTAMP_TAG_STATE,
101                PaEncTsEncStatesEnum.PA_ENC_TS_PA_TIMESTAMP_STATE,
102                UniversalTag.GENERALIZED_TIME,
103                new StorePaTimestamp() );
104
105        // --------------------------------------------------------------------------------------------
106        // Transition from patimestamp value to pausec tag
107        // --------------------------------------------------------------------------------------------
108        // PA-ENC-TS-ENC           ::= SEQUENCE {
109        //         ...
110        //         pausec          [1]
111        super.transitions[PaEncTsEncStatesEnum.PA_ENC_TS_PA_TIMESTAMP_STATE.ordinal()][KerberosConstants.PA_ENC_TS_ENC_PA_USEC_TAG] =
112            new GrammarTransition<PaEncTsEncContainer>(
113                PaEncTsEncStatesEnum.PA_ENC_TS_PA_TIMESTAMP_STATE,
114                PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_USEC_TAG_STATE,
115                KerberosConstants.PA_ENC_TS_ENC_PA_USEC_TAG,
116                new CheckNotNullLength<PaEncTsEncContainer>() );
117
118        // --------------------------------------------------------------------------------------------
119        // Transition from pausec tag to pausec value
120        // --------------------------------------------------------------------------------------------
121        // PA-ENC-TS-ENC           ::= SEQUENCE {
122        //         ...
123        //         pausec          [1] Microseconds OPTIONAL
124        // }
125        super.transitions[PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_USEC_TAG_STATE.ordinal()][UniversalTag.INTEGER
126            .getValue()] =
127            new GrammarTransition<PaEncTsEncContainer>(
128                PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_USEC_TAG_STATE,
129                PaEncTsEncStatesEnum.PA_ENC_TS_ENC_PA_USEC_STATE,
130                UniversalTag.INTEGER,
131                new StorePaUsec() );
132    }
133
134
135    /**
136     * Get the instance of this grammar
137     *
138     * @return An instance on the PA-ENC-TS-ENC Grammar
139     */
140    public static Grammar<PaEncTsEncContainer> getInstance()
141    {
142        return instance;
143    }
144}