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.crypto.checksum;
21  
22  
23  /**
24   * A type-safe enumeration of Kerberos checksum types.
25   * 
26   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
27   */
28  public enum ChecksumType implements Comparable<ChecksumType>
29  {
30      /**
31       * The "unknown" checksum type.
32       */
33      UNKNOWN(-1, "UNKNOWN"),
34  
35      /**
36       * The "null" checksum type.
37       */
38      NULL(0, "NULL"),
39  
40      /**
41       * The CRC32 checksum type (RFC3961).
42       */
43      CRC32(1, "CRC32"),
44  
45      /**
46       * The rsa-md4 checksum type (RFC3961).
47       */
48      RSA_MD4(2, "rsa-md4"),
49  
50      /**
51       * The rsa-md4-des checksum type (RFC3961).
52       */
53      RSA_MD4_DES(3, "rsa-md4-des"),
54  
55      /**
56       * The des-mac checksum type (RFC3961).
57       */
58      DES_MAC(4, "des-mac"),
59  
60      /**
61       * The des-mac-k checksum type (RFC3961).
62       */
63      DES_MAC_K(5, "rsa-md5"),
64  
65      /**
66       * The rsa-md4-des-k checksum type (RFC3961).
67       */
68      RSA_MD4_DES_K(6, "rsa-md5"),
69  
70      /**
71       * The rsa-md5 checksum type (RFC3961).
72       */
73      RSA_MD5(7, "rsa-md5"),
74  
75      /**
76       * The rsa-md5-des checksum type (RFC3961).
77       */
78      RSA_MD5_DES(8, "rsa-md5-des"),
79  
80      /**
81       * The rsa-md5-des3 checksum type.
82       */
83      RSA_MD5_DES3(9, "rsa-md5-des3"),
84  
85      /**
86       * The sha1 (unkeyed) checksum type.
87       */
88      SHA1(10, "sha1"),
89  
90      /**
91       * The hmac-sha1-des3-kd checksum type (RFC3961).
92       */
93      HMAC_SHA1_DES3_KD(12, "hmac-sha1-des3-kd"),
94  
95      /**
96       * The hmac-sha1-des3 checksum type.
97       */
98      HMAC_SHA1_DES3(13, "hmac-sha1-des3"),
99  
100     /**
101      * The sha1 (unkeyed) checksum type.
102      */
103     SHA1_2(14, "sha1"),
104 
105     /**
106      * The hmac-sha1-96-aes128 checksum type (RFC3962).
107      */
108     HMAC_SHA1_96_AES128(15, "hmac-sha1-96-aes128"),
109 
110     /**
111      * The hmac-sha1-96-aes256 checksum type (RFC3962).
112      */
113     HMAC_SHA1_96_AES256(16, "hmac-sha1-96-aes256"),
114 
115     /**
116      * The hmac-sha256-128-aes128 checksum type (RFC8009).
117      */
118     HMAC_SHA256_128_AES128(19, "hmac-sha256-128-aes128"),
119 
120     /**
121      * The hmac-sha384-192-aes256 checksum type (RFC8009).
122      */
123     HMAC_SHA384_192_AES256(20, "hmac-sha384-192-aes256"),
124 
125     /**
126      * The hmac-md5 checksum type (RFC4757).
127      */
128     HMAC_MD5(-138, "hmac-md5");
129 
130     /**
131      * The value/code for the checksum type.
132      */
133     private final int value;
134 
135     /**
136      * The name of the checksum type.
137      */
138     private final String name;
139 
140 
141     /**
142      * Private constructor prevents construction outside of this class.
143      */
144     private ChecksumType( int value, String name )
145     {
146         this.value = value;
147         this.name = name;
148     }
149 
150 
151     /**
152      * Returns the checksum type when specified by its value.
153      *
154      * @param type
155      * @return The checksum type.
156      */
157     public static ChecksumType getTypeByValue( int type )
158     {
159         switch ( type )
160         {
161             case -1:
162                 return UNKNOWN;
163             case 0:
164                 return NULL;
165             case 1:
166                 return CRC32;
167             case 2:
168                 return RSA_MD4;
169             case 3:
170                 return RSA_MD4_DES;
171             case 4:
172                 return DES_MAC;
173             case 5:
174                 return DES_MAC_K;
175             case 6:
176                 return RSA_MD4_DES_K;
177             case 7:
178                 return RSA_MD5;
179             case 8:
180                 return RSA_MD5_DES;
181             case 9:
182                 return RSA_MD5_DES3;
183             case 10:
184                 return SHA1;
185             case 12:
186                 return HMAC_SHA1_DES3_KD;
187             case 13:
188                 return HMAC_SHA1_DES3;
189             case 14:
190                 return SHA1_2;
191             case 15:
192                 return HMAC_SHA1_96_AES128;
193             case 16:
194                 return HMAC_SHA1_96_AES256;
195             case 19:
196                 return HMAC_SHA256_128_AES128;
197             case 20:
198                 return HMAC_SHA384_192_AES256;
199             case -138:
200                 return HMAC_MD5;
201             default:
202                 return UNKNOWN;
203         }
204     }
205 
206 
207     /**
208      * Returns the number associated with this checksum type.
209      *
210      * @return The checksum type value.
211      */
212     public int getValue()
213     {
214         return value;
215     }
216 
217 
218     /**
219      * Returns the name associated with this checksum type.
220      *
221      * @return The name.
222      */
223     public String getName()
224     {
225         return name;
226     }
227 
228 
229     /**
230      * @see Object#toString()
231      */
232     @Override
233     public String toString()
234     {
235         return getName() + " (" + value + ")";
236     }
237 }