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.encryptionKey;
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.encryptionKey.actions.EncryptionKeyInit;
30 import org.apache.directory.shared.kerberos.codec.encryptionKey.actions.StoreKeyType;
31 import org.apache.directory.shared.kerberos.codec.encryptionKey.actions.StoreKeyValue;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35
36 /**
37 * This class implements the EncryptionKey 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 EncryptionKeyGrammar extends AbstractGrammar<EncryptionKeyContainer>
44 {
45 /** The logger */
46 static final Logger LOG = LoggerFactory.getLogger( EncryptionKeyGrammar.class );
47
48 /** A speedup for logger */
49 static final boolean IS_DEBUG = LOG.isDebugEnabled();
50
51 /** The instance of grammar. EncryptionKeyGrammar is a singleton */
52 private static Grammar<EncryptionKeyContainer> instance = new EncryptionKeyGrammar();
53
54
55 /**
56 * Creates a new EncryptionKeyGrammar object.
57 */
58 @SuppressWarnings("unchecked")
59 private EncryptionKeyGrammar()
60 {
61 setName( EncryptionKeyGrammar.class.getName() );
62
63 // Create the transitions table
64 super.transitions = new GrammarTransition[EncryptionKeyStatesEnum.LAST_ENCRYPTION_KEY_STATE.ordinal()][256];
65
66 // ============================================================================================
67 // EncryptionKey
68 // ============================================================================================
69 // --------------------------------------------------------------------------------------------
70 // Transition from EncryptionKey init to EncryptionKey SEQ OF
71 // --------------------------------------------------------------------------------------------
72 // EncryptionKey ::= SEQUENCE {
73 super.transitions[EncryptionKeyStatesEnum.START_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
74 new GrammarTransition<EncryptionKeyContainer>(
75 EncryptionKeyStatesEnum.START_STATE,
76 EncryptionKeyStatesEnum.ENCRYPTION_KEY_SEQ_STATE,
77 UniversalTag.SEQUENCE,
78 new EncryptionKeyInit() );
79
80 // --------------------------------------------------------------------------------------------
81 // Transition from EncryptionKey SEQ to key-type tag
82 // --------------------------------------------------------------------------------------------
83 // EncryptionKey ::= SEQUENCE {
84 // keytype [0]
85 super.transitions[EncryptionKeyStatesEnum.ENCRYPTION_KEY_SEQ_STATE.ordinal()][KerberosConstants.ENCRYPTION_KEY_TYPE_TAG] =
86 new GrammarTransition<EncryptionKeyContainer>(
87 EncryptionKeyStatesEnum.ENCRYPTION_KEY_SEQ_STATE,
88 EncryptionKeyStatesEnum.ENCRYPTION_KEY_TYPE_TAG_STATE,
89 KerberosConstants.ENCRYPTION_KEY_TYPE_TAG,
90 new CheckNotNullLength<EncryptionKeyContainer>() );
91
92 // --------------------------------------------------------------------------------------------
93 // Transition from EncryptionKey type tag to key-type value
94 // --------------------------------------------------------------------------------------------
95 // EncryptionKey ::= SEQUENCE {
96 // keytype [0] Int32
97 super.transitions[EncryptionKeyStatesEnum.ENCRYPTION_KEY_TYPE_TAG_STATE.ordinal()][UniversalTag.INTEGER
98 .getValue()] =
99 new GrammarTransition<EncryptionKeyContainer>(
100 EncryptionKeyStatesEnum.ENCRYPTION_KEY_TYPE_TAG_STATE,
101 EncryptionKeyStatesEnum.ENCRYPTION_KEY_TYPE_STATE,
102 UniversalTag.INTEGER,
103 new StoreKeyType() );
104
105 // --------------------------------------------------------------------------------------------
106 // Transition from key-type to key-value tag
107 // --------------------------------------------------------------------------------------------
108 // EncryptionKey ::= SEQUENCE {
109 // ...
110 // keyvalue [2]
111 super.transitions[EncryptionKeyStatesEnum.ENCRYPTION_KEY_TYPE_STATE.ordinal()][KerberosConstants.ENCRYPTION_KEY_VALUE_TAG] =
112 new GrammarTransition<EncryptionKeyContainer>(
113 EncryptionKeyStatesEnum.ENCRYPTION_KEY_TYPE_STATE,
114 EncryptionKeyStatesEnum.ENCRYPTION_KEY_VALUE_TAG_STATE,
115 KerberosConstants.ENCRYPTION_KEY_VALUE_TAG,
116 new CheckNotNullLength<EncryptionKeyContainer>() );
117
118 // --------------------------------------------------------------------------------------------
119 // Transition from key-value tag to key-value value
120 // --------------------------------------------------------------------------------------------
121 // EncryptionKey ::= SEQUENCE {
122 // keyvalue [2] OCTET STRING
123 super.transitions[EncryptionKeyStatesEnum.ENCRYPTION_KEY_VALUE_TAG_STATE.ordinal()][UniversalTag.OCTET_STRING
124 .getValue()] =
125 new GrammarTransition<EncryptionKeyContainer>(
126 EncryptionKeyStatesEnum.ENCRYPTION_KEY_VALUE_TAG_STATE,
127 EncryptionKeyStatesEnum.ENCRYPTION_KEY_VALUE_STATE,
128 UniversalTag.OCTET_STRING,
129 new StoreKeyValue() );
130 }
131
132
133 /**
134 * Get the instance of this grammar
135 *
136 * @return An instance on the EncryptionKey Grammar
137 */
138 public static Grammar<EncryptionKeyContainer> getInstance()
139 {
140 return instance;
141 }
142 }