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 */ 019package org.apache.shiro.crypto.hash.format; 020 021import java.util.Locale; 022 023/** 024 * An enum representing Shiro's default provided {@link HashFormat} implementations. 025 * 026 * @since 1.2 027 */ 028public enum ProvidedHashFormat { 029 030 /** 031 * Value representing the {@link HexFormat} implementation. 032 */ 033 @Deprecated 034 HEX(HexFormat.class), 035 036 /** 037 * Value representing the {@link Base64Format} implementation. 038 */ 039 @Deprecated 040 BASE64(Base64Format.class), 041 042 /** 043 * Value representing the {@link Shiro1CryptFormat} implementation. 044 */ 045 SHIRO1(Shiro1CryptFormat.class), 046 047 /** 048 * Value representing the {@link Shiro2CryptFormat} implementation. 049 */ 050 SHIRO2(Shiro2CryptFormat.class); 051 052 private final Class<? extends HashFormat> clazz; 053 054 ProvidedHashFormat(final Class<? extends HashFormat> clazz) { 055 this.clazz = clazz; 056 } 057 058 Class<? extends HashFormat> getHashFormatClass() { 059 return this.clazz; 060 } 061 062 public static ProvidedHashFormat byId(final String id) { 063 if (id == null) { 064 return null; 065 } 066 try { 067 // Use English Locale, some Locales handle uppercase/lower differently. i.e. Turkish and upper case 'i' 068 // is not 'I'. And 'SHIRO1' would be 'SHİRO1' 069 return valueOf(id.toUpperCase(Locale.ENGLISH)); 070 } catch (final IllegalArgumentException ignored) { 071 return null; 072 } 073 } 074 075}