Coverage Report - org.apache.shiro.crypto.hash.SimpleHashRequest
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleHashRequest
100%
12/12
100%
2/2
1.4
 
 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  
 package org.apache.shiro.crypto.hash;
 20  
 
 21  
 import org.apache.shiro.util.ByteSource;
 22  
 
 23  
 /**
 24  
  * Simple implementation of {@link HashRequest} that can be used when interacting with a {@link HashService}.
 25  
  *
 26  
  * @since 1.2
 27  
  */
 28  
 public class SimpleHashRequest implements HashRequest {
 29  
 
 30  
     private final ByteSource source; //cannot be null - this is the source to hash.
 31  
     private final ByteSource salt; //null = no salt specified
 32  
     private final int iterations; //0 = not specified by the requestor; let the HashService decide.
 33  
     private final String algorithmName; //null = let the HashService decide.
 34  
 
 35  
     /**
 36  
      * Creates a new SimpleHashRequest instance.
 37  
      *
 38  
      * @param algorithmName the name of the hash algorithm to use.  This is often null as the
 39  
      * {@link HashService} implementation is usually configured with an appropriate algorithm name, but this
 40  
      * can be non-null if the hash service's algorithm should be overridden with a specific one for the duration
 41  
      * of the request.
 42  
      *
 43  
      * @param source the source to be hashed
 44  
      * @param salt any public salt which should be used when computing the hash
 45  
      * @param iterations the number of hash iterations to execute.  Zero (0) indicates no iterations were specified
 46  
      * for the request, at which point the number of iterations is decided by the {@code HashService}
 47  
      * @throws NullPointerException if {@code source} is null or empty.
 48  
      */
 49  32
     public SimpleHashRequest(String algorithmName, ByteSource source, ByteSource salt, int iterations) {
 50  32
         if (source == null) {
 51  1
             throw new NullPointerException("source argument cannot be null");
 52  
         }
 53  31
         this.source = source;
 54  31
         this.salt = salt;
 55  31
         this.algorithmName = algorithmName;
 56  31
         this.iterations = Math.max(0, iterations);
 57  31
     }
 58  
 
 59  
     public ByteSource getSource() {
 60  84
         return this.source;
 61  
     }
 62  
 
 63  
     public ByteSource getSalt() {
 64  28
         return this.salt;
 65  
     }
 66  
 
 67  
     public int getIterations() {
 68  29
         return iterations;
 69  
     }
 70  
 
 71  
     public String getAlgorithmName() {
 72  28
         return algorithmName;
 73  
     }
 74  
 }