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    package org.apache.shiro.crypto.hash.format;
020    
021    /**
022     * An enum representing Shiro's default provided {@link HashFormat} implementations.
023     *
024     * @since 1.2
025     */
026    public enum ProvidedHashFormat {
027    
028        /**
029         * Value representing the {@link HexFormat} implementation.
030         */
031        HEX(HexFormat.class),
032    
033        /**
034         * Value representing the {@link Base64Format} implementation.
035         */
036        BASE64(Base64Format.class),
037    
038        /**
039         * Value representing the {@link Shiro1CryptFormat} implementation.
040         */
041        SHIRO1(Shiro1CryptFormat.class);
042    
043        private final Class<? extends HashFormat> clazz;
044    
045        private ProvidedHashFormat(Class<? extends HashFormat> clazz) {
046            this.clazz = clazz;
047        }
048    
049        Class<? extends HashFormat> getHashFormatClass() {
050            return this.clazz;
051        }
052    
053        public static ProvidedHashFormat byId(String id) {
054            if (id == null) {
055                return null;
056            }
057            try {
058                return valueOf(id.toUpperCase());
059            } catch (IllegalArgumentException ignored) {
060                return null;
061            }
062        }
063    
064    }