author | chegar |
Thu, 17 Oct 2019 20:53:35 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58678 | 9cf78a70fa4f |
parent 47216 | 71c04702a3d5 |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
58678 | 2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
2 | 4 |
* |
58678 | 5 |
* This code is free software; you can redistribute it and/or modify it |
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
2 | 10 |
* |
58678 | 11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
2 | 16 |
* |
58678 | 17 |
* You should have received a copy of the GNU General Public License version |
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.pkcs11.wrapper; |
|
27 |
||
58678 | 28 |
import java.security.ProviderException; |
29 |
import java.security.spec.PSSParameterSpec; |
|
30 |
import java.security.spec.MGF1ParameterSpec; |
|
2 | 31 |
|
32 |
||
33 |
/** |
|
58678 | 34 |
* This class represents the necessary parameters required by the |
35 |
* CKM_RSA_PKCS_PSS mechanism as defined in CK_RSA_PKCS_PSS_PARAMS structure.<p> |
|
2 | 36 |
* <B>PKCS#11 structure:</B> |
37 |
* <PRE> |
|
38 |
* typedef struct CK_RSA_PKCS_PSS_PARAMS { |
|
58678 | 39 |
* CK_MECHANISM_TYPE hashAlg; |
40 |
* CK_RSA_PKCS_MGF_TYPE mgf; |
|
41 |
* CK_ULONG sLen; |
|
2 | 42 |
* } CK_RSA_PKCS_PSS_PARAMS; |
43 |
* </PRE> |
|
44 |
* |
|
58678 | 45 |
* @since 13 |
2 | 46 |
*/ |
47 |
public class CK_RSA_PKCS_PSS_PARAMS { |
|
48 |
||
58678 | 49 |
private final long hashAlg; |
50 |
private final long mgf; |
|
51 |
private final long sLen; |
|
52 |
||
53 |
public CK_RSA_PKCS_PSS_PARAMS(String hashAlg, String mgfAlg, |
|
54 |
String mgfHash, int sLen) { |
|
55 |
this.hashAlg = Functions.getHashMechId(hashAlg); |
|
56 |
if (!mgfAlg.equals("MGF1")) { |
|
57 |
throw new ProviderException("Only MGF1 is supported"); |
|
58 |
} |
|
59 |
// no dash in PKCS#11 mechanism names |
|
60 |
this.mgf = Functions.getMGFId("CKG_MGF1_" + mgfHash.replaceFirst("-", "")); |
|
61 |
this.sLen = sLen; |
|
62 |
} |
|
2 | 63 |
|
58678 | 64 |
@Override |
65 |
public boolean equals(Object o) { |
|
66 |
if (o == this) { |
|
67 |
return true; |
|
68 |
} |
|
69 |
||
70 |
if (!(o instanceof CK_RSA_PKCS_PSS_PARAMS)) { |
|
71 |
return false; |
|
72 |
} |
|
2 | 73 |
|
58678 | 74 |
CK_RSA_PKCS_PSS_PARAMS other = (CK_RSA_PKCS_PSS_PARAMS) o; |
75 |
return ((other.hashAlg == hashAlg) && |
|
76 |
(other.mgf == mgf) && |
|
77 |
(other.sLen == sLen)); |
|
78 |
} |
|
2 | 79 |
|
58678 | 80 |
@Override |
81 |
public int hashCode() { |
|
82 |
return (int)(hashAlg << 2 + mgf << 1 + sLen); |
|
83 |
} |
|
84 |
||
85 |
@Override |
|
2 | 86 |
public String toString() { |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
87 |
StringBuilder sb = new StringBuilder(); |
2 | 88 |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
89 |
sb.append(Constants.INDENT); |
58678 | 90 |
sb.append("hashAlg: "); |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
91 |
sb.append(Functions.toFullHexString(hashAlg)); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
92 |
sb.append(Constants.NEWLINE); |
2 | 93 |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
94 |
sb.append(Constants.INDENT); |
58678 | 95 |
sb.append("mgf: "); |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
96 |
sb.append(Functions.toFullHexString(mgf)); |
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
97 |
sb.append(Constants.NEWLINE); |
2 | 98 |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
99 |
sb.append(Constants.INDENT); |
58678 | 100 |
sb.append("sLen(in bytes): "); |
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
101 |
sb.append(sLen); |
2 | 102 |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
2
diff
changeset
|
103 |
return sb.toString(); |
2 | 104 |
} |
105 |
} |