001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.shared.kerberos.crypto.checksum; 021 022 023/** 024 * A type-safe enumeration of Kerberos checksum types. 025 * 026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 027 */ 028public enum ChecksumType implements Comparable<ChecksumType> 029{ 030 /** 031 * The "unknown" checksum type. 032 */ 033 UNKNOWN(-1, "UNKNOWN"), 034 035 /** 036 * The "null" checksum type. 037 */ 038 NULL(0, "NULL"), 039 040 /** 041 * The CRC32 checksum type (RFC3961). 042 */ 043 CRC32(1, "CRC32"), 044 045 /** 046 * The rsa-md4 checksum type (RFC3961). 047 */ 048 RSA_MD4(2, "rsa-md4"), 049 050 /** 051 * The rsa-md4-des checksum type (RFC3961). 052 */ 053 RSA_MD4_DES(3, "rsa-md4-des"), 054 055 /** 056 * The des-mac checksum type (RFC3961). 057 */ 058 DES_MAC(4, "des-mac"), 059 060 /** 061 * The des-mac-k checksum type (RFC3961). 062 */ 063 DES_MAC_K(5, "rsa-md5"), 064 065 /** 066 * The rsa-md4-des-k checksum type (RFC3961). 067 */ 068 RSA_MD4_DES_K(6, "rsa-md5"), 069 070 /** 071 * The rsa-md5 checksum type (RFC3961). 072 */ 073 RSA_MD5(7, "rsa-md5"), 074 075 /** 076 * The rsa-md5-des checksum type (RFC3961). 077 */ 078 RSA_MD5_DES(8, "rsa-md5-des"), 079 080 /** 081 * The rsa-md5-des3 checksum type. 082 */ 083 RSA_MD5_DES3(9, "rsa-md5-des3"), 084 085 /** 086 * The sha1 (unkeyed) checksum type. 087 */ 088 SHA1(10, "sha1"), 089 090 /** 091 * The hmac-sha1-des3-kd checksum type (RFC3961). 092 */ 093 HMAC_SHA1_DES3_KD(12, "hmac-sha1-des3-kd"), 094 095 /** 096 * The hmac-sha1-des3 checksum type. 097 */ 098 HMAC_SHA1_DES3(13, "hmac-sha1-des3"), 099 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}