1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.crypto.signer.params

File PssParameters.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

2
15
10
1
142
56
11
0.73
1.5
10
1.1

Classes

Class Line # Actions
PssParameters 28 15 0% 11 8
0.703703770.4%
 

Contributing tests

This file is covered by 8 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.crypto.signer.params;
21   
22    /**
23    * PSS parameters.
24    *
25    * @version $Id: 039f72d61129ef3c5e5675e24148a6709f63e3ca $
26    * @since 5.4RC1
27    */
 
28    public class PssParameters
29    {
30    private static final String DEFAULT_DIGEST = "SHA-1";
31   
32    private static final byte TRAILER_1 = (byte) 0xBC;
33   
34    private final String hashAlgorithm;
35   
36    private final String maskGenAlgorithm;
37   
38    private final int saltLength;
39   
40    private final int trailerField;
41   
42    /**
43    * Construct default RSASSA-PSS parameters according to PKCS #1 definition of default value.
44    */
 
45  0 toggle public PssParameters()
46    {
47  0 this(DEFAULT_DIGEST);
48    }
49   
50    /**
51    * Construct RSASSA-PSS parameters using default trailer and the same digest algorithm for both hash and mgf1.
52    *
53    * @param hashAlgorithm digest algorithm to use for hash and mgf1.
54    */
 
55  0 toggle public PssParameters(String hashAlgorithm)
56    {
57  0 this(hashAlgorithm, -1);
58    }
59   
60    /**
61    * Construct RSASSA-PSS parameters using default trailer and the same digest algorithm for both hash and mgf1.
62    *
63    * @param hashAlgorithm digest algorithm to use for hash and mgf1.
64    * @param saltLength size of salt in bytes.
65    */
 
66  12 toggle public PssParameters(String hashAlgorithm, int saltLength)
67    {
68  12 this(hashAlgorithm, hashAlgorithm, saltLength, 1);
69    }
70   
71    /**
72    * Construct RSASSA-PSS parameters using custom parameters.
73    *
74    * @param hashAlgorithm digest algorithm to use for hash.
75    * @param maskGenAlgorithm digest algorithm to use for mgf1.
76    * @param saltLength size of salt in bytes, -1 means use the digest size.
77    */
 
78  0 toggle public PssParameters(String hashAlgorithm, String maskGenAlgorithm, int saltLength)
79    {
80  0 this(hashAlgorithm, maskGenAlgorithm, saltLength, 1);
81    }
82   
83    /**
84    * Construct RSASSA-PSS parameters using custom parameters.
85    *
86    * @param hashAlgorithm digest algorithm to use for hash.
87    * @param maskGenAlgorithm digest algorithm to use for mgf1.
88    * @param saltLength size of salt in bytes, -1 means use the digest size.
89    * @param trailerField trailer selection, only valid value is 1.
90    */
 
91  16 toggle public PssParameters(String hashAlgorithm, String maskGenAlgorithm, int saltLength, int trailerField)
92    {
93  16 this.hashAlgorithm = hashAlgorithm;
94  16 this.maskGenAlgorithm = maskGenAlgorithm;
95  16 this.saltLength = saltLength;
96  16 this.trailerField = trailerField;
97    }
98   
99    /**
100    * @return digest algorithm to use for hash.
101    */
 
102  32 toggle public String getHashAlgorithm()
103    {
104  32 return this.hashAlgorithm;
105    }
106   
107    /**
108    * @return digest algorithm to use for mgf1.
109    */
 
110  32 toggle public String getMaskGenAlgorithm()
111    {
112  32 return this.maskGenAlgorithm;
113    }
114   
115    /**
116    * @return size of salt in bytes.
117    */
 
118  40 toggle public int getSaltLength()
119    {
120  40 return this.saltLength;
121    }
122   
123    /**
124    * @return trailer field.
125    */
 
126  16 toggle public int getTrailerField()
127    {
128  16 return this.trailerField;
129    }
130   
131    /**
132    * @return trailer byte.
133    */
 
134  16 toggle public byte getTrailerByte()
135    {
136  16 if (this.trailerField == 1) {
137  16 return TRAILER_1;
138    }
139   
140  0 throw new IllegalArgumentException("Unknown trailer field.");
141    }
142    }