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 module hunt.shiro.crypto.hash.Sha384Hash;
20 
21 import hunt.shiro.crypto.hash.SimpleHash;
22 
23 import hunt.shiro.codec.Base64;
24 import hunt.shiro.codec.Hex;
25 
26 
27 /**
28  * Generates an SHA-384 Hash from a given input <tt>source</tt> with an optional <tt>salt</tt> and hash iterations.
29  * <p/>
30  * See the {@link SimpleHash SimpleHash} parent class JavaDoc for a detailed explanation of Hashing
31  * techniques and how the overloaded constructors function.
32  * <p/>
33  * <b>JDK Version Note</b> - Attempting to instantiate this class on JREs prior to version 1.4.0 will throw
34  * an {@link IllegalStateException IllegalStateException}
35  *
36  */
37 class Sha384Hash : SimpleHash {
38 
39     //TODO - complete JavaDoc
40 
41     enum string ALGORITHM_NAME = "SHA-384";
42 
43     this() {
44         super(ALGORITHM_NAME);
45     }
46 
47     this(Object source) {
48         super(ALGORITHM_NAME, source);
49     }
50 
51     this(Object source, Object salt) {
52         super(ALGORITHM_NAME, source, salt);
53     }
54 
55     this(Object source, Object salt, int hashIterations) {
56         super(ALGORITHM_NAME, source, salt, hashIterations);
57     }
58 
59     static Sha384Hash fromHexString(string hex) {
60         Sha384Hash hash = new Sha384Hash();
61         hash.setBytes(Hex.decode(hex));
62         return hash;
63     }
64 
65     static Sha384Hash fromBase64String(string base64) {
66         Sha384Hash hash = new Sha384Hash();
67         hash.setBytes(Base64.decode(base64));
68         return hash;
69     }
70 }