View Javadoc
1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License.
18   *
19   */
20  package org.apache.directory.shared.kerberos.codec.etypeInfoEntry;
21  
22  
23  import org.apache.directory.api.asn1.actions.CheckNotNullLength;
24  import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
25  import org.apache.directory.api.asn1.ber.grammar.Grammar;
26  import org.apache.directory.api.asn1.ber.grammar.GrammarTransition;
27  import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
28  import org.apache.directory.shared.kerberos.KerberosConstants;
29  import org.apache.directory.shared.kerberos.codec.etypeInfoEntry.actions.ETypeInfoEntryInit;
30  import org.apache.directory.shared.kerberos.codec.etypeInfoEntry.actions.StoreEType;
31  import org.apache.directory.shared.kerberos.codec.etypeInfoEntry.actions.StoreSalt;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  
35  
36  /**
37   * This class implements the ETYPE-INFO-ENTRY structure. All the actions are declared
38   * in this class. As it is a singleton, these declaration are only done once. If
39   * an action is to be added or modified, this is where the work is to be done !
40   *
41   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
42   */
43  public final class ETypeInfoEntryGrammar extends AbstractGrammar<ETypeInfoEntryContainer>
44  {
45      /** The logger */
46      static final Logger LOG = LoggerFactory.getLogger( ETypeInfoEntryGrammar.class );
47  
48      /** A speedup for logger */
49      static final boolean IS_DEBUG = LOG.isDebugEnabled();
50  
51      /** The instance of grammar. ETypeInfoEntryGrammar is a singleton */
52      private static Grammar<ETypeInfoEntryContainer> instance = new ETypeInfoEntryGrammar();
53  
54  
55      /**
56       * Creates a new ETypeInfoEntryGrammar object.
57       */
58      @SuppressWarnings("unchecked")
59      private ETypeInfoEntryGrammar()
60      {
61          setName( ETypeInfoEntryGrammar.class.getName() );
62  
63          // Create the transitions table
64          super.transitions = new GrammarTransition[ETypeInfoEntryStatesEnum.LAST_ETYPE_INFO_ENTRY_STATE.ordinal()][256];
65  
66          // ============================================================================================
67          // ETYPE-INFO-ENTRY
68          // ============================================================================================
69          // --------------------------------------------------------------------------------------------
70          // Transition from ETYPE-INFO-ENTRY init to ETYPE-INFO-ENTRY SEQ
71          // --------------------------------------------------------------------------------------------
72          // ETYPE-INFO-ENTRY         ::= SEQUENCE {
73          super.transitions[ETypeInfoEntryStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
74              new GrammarTransition<ETypeInfoEntryContainer>(
75                  ETypeInfoEntryStatesEnum.START_STATE,
76                  ETypeInfoEntryStatesEnum.ETYPE_INFO_ENTRY_SEQ_STATE,
77                  UniversalTag.SEQUENCE,
78                  new ETypeInfoEntryInit() );
79  
80          // --------------------------------------------------------------------------------------------
81          // Transition from ETYPE-INFO-ENTRY SEQ to etype tag
82          // --------------------------------------------------------------------------------------------
83          // ETYPE-INFO-ENTRY         ::= SEQUENCE {
84          //         etype           [0]
85          super.transitions[ETypeInfoEntryStatesEnum.ETYPE_INFO_ENTRY_SEQ_STATE.ordinal()][KerberosConstants.TRANSITED_ENCODING_TR_TYPE_TAG] =
86              new GrammarTransition<ETypeInfoEntryContainer>(
87                  ETypeInfoEntryStatesEnum.ETYPE_INFO_ENTRY_SEQ_STATE,
88                  ETypeInfoEntryStatesEnum.ETYPE_INFO_ENTRY_ETYPE_TAG_STATE,
89                  KerberosConstants.TRANSITED_ENCODING_TR_TYPE_TAG,
90                  new CheckNotNullLength<ETypeInfoEntryContainer>() );
91  
92          // --------------------------------------------------------------------------------------------
93          // Transition from etype tag to etype value
94          // --------------------------------------------------------------------------------------------
95          // ETYPE-INFO-ENTRY         ::= SEQUENCE {
96          //         etype           [0] Int32,
97          super.transitions[ETypeInfoEntryStatesEnum.ETYPE_INFO_ENTRY_ETYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER
98              .getValue()] =
99              new GrammarTransition<ETypeInfoEntryContainer>(
100                 ETypeInfoEntryStatesEnum.ETYPE_INFO_ENTRY_ETYPE_TAG_STATE,
101                 ETypeInfoEntryStatesEnum.ETYPE_INFO_ENTRY_ETYPE_STATE,
102                 UniversalTag.INTEGER,
103                 new StoreEType() );
104 
105         // --------------------------------------------------------------------------------------------
106         // Transition from etype value to salt tag
107         // --------------------------------------------------------------------------------------------
108         // ETYPE-INFO-ENTRY         ::= SEQUENCE {
109         //         ...
110         //         salt            [1]
111         super.transitions[ETypeInfoEntryStatesEnum.ETYPE_INFO_ENTRY_ETYPE_STATE.ordinal()][KerberosConstants.TRANSITED_ENCODING_CONTENTS_TAG] =
112             new GrammarTransition<ETypeInfoEntryContainer>(
113                 ETypeInfoEntryStatesEnum.ETYPE_INFO_ENTRY_ETYPE_STATE,
114                 ETypeInfoEntryStatesEnum.ETYPE_INFO_ENTRY_SALT_TAG_STATE,
115                 KerberosConstants.TRANSITED_ENCODING_CONTENTS_TAG,
116                 new CheckNotNullLength<ETypeInfoEntryContainer>() );
117 
118         // --------------------------------------------------------------------------------------------
119         // Transition from salt tag to salt value
120         // --------------------------------------------------------------------------------------------
121         // ETYPE-INFO-ENTRY         ::= SEQUENCE {
122         //         ...
123         //         salt            [1] OCTET STRING OPTIONAL
124         super.transitions[ETypeInfoEntryStatesEnum.ETYPE_INFO_ENTRY_SALT_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING
125             .getValue()] =
126             new GrammarTransition<ETypeInfoEntryContainer>(
127                 ETypeInfoEntryStatesEnum.ETYPE_INFO_ENTRY_SALT_TAG_STATE,
128                 ETypeInfoEntryStatesEnum.ETYPE_INFO_ENTRY_SALT_STATE,
129                 UniversalTag.OCTET_STRING,
130                 new StoreSalt() );
131     }
132 
133 
134     /**
135      * Get the instance of this grammar
136      *
137      * @return An instance on the ETYPE-INFO-ENTRY Grammar
138      */
139     public static Grammar<ETypeInfoEntryContainer> getInstance()
140     {
141         return instance;
142     }
143 }