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.encApRepPart;
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.encApRepPart.actions.EncApRepPartInit;
30 import org.apache.directory.shared.kerberos.codec.encApRepPart.actions.StoreCTime;
31 import org.apache.directory.shared.kerberos.codec.encApRepPart.actions.StoreCusec;
32 import org.apache.directory.shared.kerberos.codec.encApRepPart.actions.StoreSeqNumber;
33 import org.apache.directory.shared.kerberos.codec.encApRepPart.actions.StoreSubKey;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37
38 /**
39 * This class implements the EncApRepPart structure. All the actions are declared
40 * in this class. As it is a singleton, these declaration are only done once. If
41 * an action is to be added or modified, this is where the work is to be done !
42 *
43 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
44 */
45 public final class EncApRepPartGrammar extends AbstractGrammar<EncApRepPartContainer>
46 {
47 /** The logger */
48 static final Logger LOG = LoggerFactory.getLogger( EncApRepPartGrammar.class );
49
50 /** A speedup for logger */
51 static final boolean IS_DEBUG = LOG.isDebugEnabled();
52
53 /** The instance of grammar. EncApRepPartGrammar is a singleton */
54 private static Grammar<EncApRepPartContainer> instance = new EncApRepPartGrammar();
55
56
57 /**
58 * Creates a new EncApRepPartGrammar object.
59 */
60 @SuppressWarnings("unchecked")
61 private EncApRepPartGrammar()
62 {
63 setName( EncApRepPartGrammar.class.getName() );
64
65 // Create the transitions table
66 super.transitions = new GrammarTransition[EncApRepPartStatesEnum.LAST_ENC_AP_REP_PART_STATE.ordinal()][256];
67
68 // ============================================================================================
69 // EncApRepPart
70 // ============================================================================================
71 // --------------------------------------------------------------------------------------------
72 // Transition from EncApRepPart init to APPLICATION tag
73 // --------------------------------------------------------------------------------------------
74 // EncAPRepPart ::= [APPLICATION 27]
75 super.transitions[EncApRepPartStatesEnum.START_STATE.ordinal()][KerberosConstants.ENC_AP_REP_PART_TAG] =
76 new GrammarTransition<EncApRepPartContainer>(
77 EncApRepPartStatesEnum.START_STATE,
78 EncApRepPartStatesEnum.ENC_AP_REP_PART_STATE,
79 KerberosConstants.ENC_AP_REP_PART_TAG,
80 new EncApRepPartInit() );
81
82 // --------------------------------------------------------------------------------------------
83 // Transition from EncApRepPart APPLICATION to EncApRepPart SEQ
84 // --------------------------------------------------------------------------------------------
85 // EncAPRepPart ::= [APPLICATION 27] SEQUENCE {
86 super.transitions[EncApRepPartStatesEnum.ENC_AP_REP_PART_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
87 new GrammarTransition<EncApRepPartContainer>(
88 EncApRepPartStatesEnum.ENC_AP_REP_PART_STATE,
89 EncApRepPartStatesEnum.ENC_AP_REP_PART_SEQ_STATE,
90 UniversalTag.SEQUENCE,
91 new CheckNotNullLength<EncApRepPartContainer>() );
92
93 // --------------------------------------------------------------------------------------------
94 // Transition from EncApRepPart SEQ to ctime tag
95 // --------------------------------------------------------------------------------------------
96 // EncAPRepPart ::= [APPLICATION 27] SEQUENCE {
97 // ctime [0]
98 super.transitions[EncApRepPartStatesEnum.ENC_AP_REP_PART_SEQ_STATE.ordinal()][KerberosConstants.ENC_AP_REP_PART_CTIME_TAG] =
99 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 }