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.etypeInfo2Entry;
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.etypeInfo2Entry.actions.ETypeInfo2EntryInit;
30 import org.apache.directory.shared.kerberos.codec.etypeInfo2Entry.actions.StoreEType;
31 import org.apache.directory.shared.kerberos.codec.etypeInfo2Entry.actions.StoreS2KParams;
32 import org.apache.directory.shared.kerberos.codec.etypeInfo2Entry.actions.StoreSalt;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36
37 /**
38 * This class implements the ETYPE-INFO2-ENTRY structure. All the actions are declared
39 * in this class. As it is a singleton, these declaration are only done once. If
40 * an action is to be added or modified, this is where the work is to be done !
41 *
42 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
43 */
44 public final class ETypeInfo2EntryGrammar extends AbstractGrammar<ETypeInfo2EntryContainer>
45 {
46 /** The logger */
47 static final Logger LOG = LoggerFactory.getLogger( ETypeInfo2EntryGrammar.class );
48
49 /** A speedup for logger */
50 static final boolean IS_DEBUG = LOG.isDebugEnabled();
51
52 /** The instance of grammar. ETypeInfo2EntryGrammar is a singleton */
53 private static Grammar<ETypeInfo2EntryContainer> instance = new ETypeInfo2EntryGrammar();
54
55
56 /**
57 * Creates a new ETypeInfoEntryGrammar object.
58 */
59 @SuppressWarnings("unchecked")
60 private ETypeInfo2EntryGrammar()
61 {
62 setName( ETypeInfo2EntryGrammar.class.getName() );
63
64 // Create the transitions table
65 super.transitions = new GrammarTransition[ETypeInfo2EntryStatesEnum.LAST_ETYPE_INFO2_ENTRY_STATE.ordinal()][256];
66
67 // ============================================================================================
68 // ETYPE-INFO2-ENTRY
69 // ============================================================================================
70 // --------------------------------------------------------------------------------------------
71 // Transition from ETYPE-INFO2-ENTRY init to ETYPE-INFO2-ENTRY SEQ
72 // --------------------------------------------------------------------------------------------
73 // ETYPE-INFO2-ENTRY ::= SEQUENCE {
74 super.transitions[ETypeInfo2EntryStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
75 new GrammarTransition<ETypeInfo2EntryContainer>(
76 ETypeInfo2EntryStatesEnum.START_STATE,
77 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SEQ_STATE,
78 UniversalTag.SEQUENCE,
79 new ETypeInfo2EntryInit() );
80
81 // --------------------------------------------------------------------------------------------
82 // Transition from ETYPE-INFO2-ENTRY SEQ to etype tag
83 // --------------------------------------------------------------------------------------------
84 // ETYPE-INFO2-ENTRY ::= SEQUENCE {
85 // etype [0]
86 super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SEQ_STATE.ordinal()][KerberosConstants.ETYPE_INFO2_ENTRY_ETYPE_TAG] =
87 new GrammarTransition<ETypeInfo2EntryContainer>(
88 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SEQ_STATE,
89 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_TAG_STATE,
90 KerberosConstants.ETYPE_INFO2_ENTRY_ETYPE_TAG,
91 new CheckNotNullLength<ETypeInfo2EntryContainer>() );
92
93 // --------------------------------------------------------------------------------------------
94 // Transition from etype tag to etype value
95 // --------------------------------------------------------------------------------------------
96 // ETYPE-INFO2-ENTRY ::= SEQUENCE {
97 // etype [0] Int32,
98 super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER
99 .getValue()] =
100 new GrammarTransition<ETypeInfo2EntryContainer>(
101 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_TAG_STATE,
102 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_STATE,
103 UniversalTag.INTEGER,
104 new StoreEType() );
105
106 // --------------------------------------------------------------------------------------------
107 // Transition from etype value to salt tag
108 // --------------------------------------------------------------------------------------------
109 // ETYPE-INFO2-ENTRY ::= SEQUENCE {
110 // ...
111 // salt [1]
112 super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_STATE.ordinal()][KerberosConstants.ETYPE_INFO2_ENTRY_SALT_TAG] =
113 new GrammarTransition<ETypeInfo2EntryContainer>(
114 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_STATE,
115 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SALT_TAG_STATE,
116 KerberosConstants.ETYPE_INFO2_ENTRY_SALT_TAG,
117 new CheckNotNullLength<ETypeInfo2EntryContainer>() );
118
119 // --------------------------------------------------------------------------------------------
120 // Transition from etype value to s2kparams tag
121 // --------------------------------------------------------------------------------------------
122 // ETYPE-INFO2-ENTRY ::= SEQUENCE {
123 // ...
124 // s2kparams [2]
125 super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_STATE.ordinal()][KerberosConstants.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG] =
126 new GrammarTransition<ETypeInfo2EntryContainer>(
127 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_ETYPE_STATE,
128 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG_STATE,
129 KerberosConstants.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG,
130 new CheckNotNullLength<ETypeInfo2EntryContainer>() );
131
132 // --------------------------------------------------------------------------------------------
133 // Transition from salt tag to salt value
134 // --------------------------------------------------------------------------------------------
135 // ETYPE-INFO2-ENTRY ::= SEQUENCE {
136 // ...
137 // salt [1] KerberosString OPTIONAL,
138 super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SALT_TAG_STATE.ordinal()][UniversalTag.GENERAL_STRING
139 .getValue()] =
140 new GrammarTransition<ETypeInfo2EntryContainer>(
141 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SALT_TAG_STATE,
142 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SALT_STATE,
143 UniversalTag.GENERAL_STRING,
144 new StoreSalt() );
145
146 // --------------------------------------------------------------------------------------------
147 // Transition from salt value to s2kparams tag
148 // --------------------------------------------------------------------------------------------
149 // ETYPE-INFO2-ENTRY ::= SEQUENCE {
150 // ...
151 // s2kparams [2]
152 super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SALT_STATE.ordinal()][KerberosConstants.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG] =
153 new GrammarTransition<ETypeInfo2EntryContainer>(
154 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_SALT_STATE,
155 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG_STATE,
156 KerberosConstants.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG,
157 new CheckNotNullLength<ETypeInfo2EntryContainer>() );
158
159 // --------------------------------------------------------------------------------------------
160 // Transition from s2kparams tag to s2kparams value
161 // --------------------------------------------------------------------------------------------
162 // ETYPE-INFO2-ENTRY ::= SEQUENCE {
163 // ...
164 // s2kparams [2] OCTET STRING OPTIONAL
165 super.transitions[ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING
166 .getValue()] =
167 new GrammarTransition<ETypeInfo2EntryContainer>(
168 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_S2KPARAMS_TAG_STATE,
169 ETypeInfo2EntryStatesEnum.ETYPE_INFO2_ENTRY_S2KPARAMS_STATE,
170 UniversalTag.OCTET_STRING,
171 new StoreS2KParams() );
172 }
173
174
175 /**
176 * Get the instance of this grammar
177 *
178 * @return An instance on the ETYPE-INFO2-ENTRY Grammar
179 */
180 public static Grammar<ETypeInfo2EntryContainer> getInstance()
181 {
182 return instance;
183 }
184 }