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.typedData;
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.typedData.actions.StoreDataValue;
30 import org.apache.directory.shared.kerberos.codec.typedData.actions.StoreTdType;
31 import org.apache.directory.shared.kerberos.codec.typedData.actions.TypedDataInit;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35
36 /**
37 * This class implements the TypedData 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 TypedDataGrammar extends AbstractGrammar<TypedDataContainer>
44 {
45 /** The logger */
46 static final Logger LOG = LoggerFactory.getLogger( TypedDataGrammar.class );
47
48 /** A speedup for logger */
49 static final boolean IS_DEBUG = LOG.isDebugEnabled();
50
51 /** The instance of grammar. TypedDataGrammar is a singleton */
52 private static Grammar<TypedDataContainer> instance = new TypedDataGrammar();
53
54
55 /**
56 * Creates a new TypedDataGrammar object.
57 */
58 @SuppressWarnings("unchecked")
59 private TypedDataGrammar()
60 {
61 setName( TypedDataGrammar.class.getName() );
62
63 // Create the transitions table
64 super.transitions = new GrammarTransition[TypedDataStatesEnum.LAST_TYPED_DATA_STATE.ordinal()][256];
65
66 // ============================================================================================
67 // TypedData
68 // ============================================================================================
69 // --------------------------------------------------------------------------------------------
70 // Transition from TypedData init to TypedData SEQ OF
71 // --------------------------------------------------------------------------------------------
72 // TypedData ::= SEQUENCE OF
73 super.transitions[TypedDataStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
74 new GrammarTransition<TypedDataContainer>(
75 TypedDataStatesEnum.START_STATE,
76 TypedDataStatesEnum.TYPED_DATA_SEQ_SEQ_STATE,
77 UniversalTag.SEQUENCE,
78 new TypedDataInit() );
79
80 // --------------------------------------------------------------------------------------------
81 // Transition from TypedData SEQ OF to SEQ
82 // --------------------------------------------------------------------------------------------
83 // TypedData ::= SEQUENCE OF SEQUENCE {
84 super.transitions[TypedDataStatesEnum.TYPED_DATA_SEQ_SEQ_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
85 new GrammarTransition<TypedDataContainer>(
86 TypedDataStatesEnum.TYPED_DATA_SEQ_SEQ_STATE,
87 TypedDataStatesEnum.TYPED_DATA_SEQ_STATE,
88 UniversalTag.SEQUENCE,
89 new CheckNotNullLength<TypedDataContainer>() );
90
91 // --------------------------------------------------------------------------------------------
92 // Transition from TypedData SEQ OF to tdType tag
93 // --------------------------------------------------------------------------------------------
94 // TypedData ::= SEQUENCE OF SEQUENCE {
95 // data-type [0]
96 super.transitions[TypedDataStatesEnum.TYPED_DATA_SEQ_STATE.ordinal()][KerberosConstants.TYPED_DATA_TDTYPE_TAG] =
97 new GrammarTransition<TypedDataContainer>(
98 TypedDataStatesEnum.TYPED_DATA_SEQ_STATE,
99 TypedDataStatesEnum.TYPED_DATA_TDTYPE_TAG_STATE,
100 KerberosConstants.TYPED_DATA_TDTYPE_TAG,
101 new CheckNotNullLength<TypedDataContainer>() );
102
103 // --------------------------------------------------------------------------------------------
104 // Transition from adtype tag to tdtype value
105 // --------------------------------------------------------------------------------------------
106 // TypedData ::= SEQUENCE OF SEQUENCE {
107 // data-type [0] Int32,
108 super.transitions[TypedDataStatesEnum.TYPED_DATA_TDTYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER.getValue()] =
109 new GrammarTransition<TypedDataContainer>(
110 TypedDataStatesEnum.TYPED_DATA_TDTYPE_TAG_STATE,
111 TypedDataStatesEnum.TYPED_DATA_TDTYPE_STATE,
112 UniversalTag.INTEGER,
113 new StoreTdType() );
114
115 // --------------------------------------------------------------------------------------------
116 // Transition from ad-type value to ad-data tag
117 // --------------------------------------------------------------------------------------------
118 // TypedData ::= SEQUENCE OF SEQUENCE {
119 // ...
120 // data-value [1]
121 super.transitions[TypedDataStatesEnum.TYPED_DATA_TDTYPE_STATE.ordinal()][KerberosConstants.TYPED_DATA_TDDATA_TAG] =
122 new GrammarTransition<TypedDataContainer>(
123 TypedDataStatesEnum.TYPED_DATA_TDTYPE_STATE,
124 TypedDataStatesEnum.TYPED_DATA_TDDATA_TAG_STATE,
125 KerberosConstants.TYPED_DATA_TDDATA_TAG,
126 new CheckNotNullLength<TypedDataContainer>() );
127
128 // --------------------------------------------------------------------------------------------
129 // Transition from ad-data tag to ad-data value
130 // --------------------------------------------------------------------------------------------
131 // TypedData ::= SEQUENCE OF SEQUENCE {
132 // ...
133 // data-value [1] (OCTET STRING)
134 super.transitions[TypedDataStatesEnum.TYPED_DATA_TDDATA_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING
135 .getValue()] =
136 new GrammarTransition<TypedDataContainer>(
137 TypedDataStatesEnum.TYPED_DATA_TDDATA_TAG_STATE,
138 TypedDataStatesEnum.TYPED_DATA_TDDATA_STATE,
139 UniversalTag.OCTET_STRING,
140 new StoreDataValue() );
141
142 // --------------------------------------------------------------------------------------------
143 // Transition from ad-data value to SEQUENCE
144 // --------------------------------------------------------------------------------------------
145 // TypedData ::= SEQUENCE {
146 // ...
147 // data-value [1] (OCTET STRING)
148 super.transitions[TypedDataStatesEnum.TYPED_DATA_TDDATA_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
149 new GrammarTransition<TypedDataContainer>(
150 TypedDataStatesEnum.TYPED_DATA_TDDATA_STATE,
151 TypedDataStatesEnum.TYPED_DATA_SEQ_STATE,
152 UniversalTag.SEQUENCE,
153 new CheckNotNullLength<TypedDataContainer>() );
154 }
155
156
157 // ~ Methods
158 // ------------------------------------------------------------------------------------
159
160 /**
161 * Get the instance of this grammar
162 *
163 * @return An instance on the TypedData Grammar
164 */
165 public static Grammar<TypedDataContainer> getInstance()
166 {
167 return instance;
168 }
169 }