2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
*/
|
|
4 |
|
|
5 |
/* Copyright (c) 2002 Graz University of Technology. All rights reserved.
|
|
6 |
*
|
|
7 |
* Redistribution and use in source and binary forms, with or without
|
|
8 |
* modification, are permitted provided that the following conditions are met:
|
|
9 |
*
|
|
10 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
11 |
* this list of conditions and the following disclaimer.
|
|
12 |
*
|
|
13 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14 |
* this list of conditions and the following disclaimer in the documentation
|
|
15 |
* and/or other materials provided with the distribution.
|
|
16 |
*
|
|
17 |
* 3. The end-user documentation included with the redistribution, if any, must
|
|
18 |
* include the following acknowledgment:
|
|
19 |
*
|
|
20 |
* "This product includes software developed by IAIK of Graz University of
|
|
21 |
* Technology."
|
|
22 |
*
|
|
23 |
* Alternately, this acknowledgment may appear in the software itself, if
|
|
24 |
* and wherever such third-party acknowledgments normally appear.
|
|
25 |
*
|
|
26 |
* 4. The names "Graz University of Technology" and "IAIK of Graz University of
|
|
27 |
* Technology" must not be used to endorse or promote products derived from
|
|
28 |
* this software without prior written permission.
|
|
29 |
*
|
|
30 |
* 5. Products derived from this software may not be called
|
|
31 |
* "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior
|
|
32 |
* written permission of Graz University of Technology.
|
|
33 |
*
|
|
34 |
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
|
|
35 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
36 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
37 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE
|
|
38 |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|
39 |
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
40 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
41 |
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
42 |
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
43 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
44 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
45 |
* POSSIBILITY OF SUCH DAMAGE.
|
|
46 |
*/
|
|
47 |
|
|
48 |
package sun.security.pkcs11.wrapper;
|
|
49 |
|
|
50 |
import java.math.BigInteger;
|
|
51 |
|
|
52 |
/**
|
|
53 |
* class CK_MECHANISM specifies a particular mechanism and any parameters it
|
|
54 |
* requires.<p>
|
|
55 |
* <B>PKCS#11 structure:</B>
|
|
56 |
* <PRE>
|
|
57 |
* typedef struct CK_MECHANISM {
|
|
58 |
* CK_MECHANISM_TYPE mechanism;
|
|
59 |
* CK_VOID_PTR pParameter;
|
|
60 |
* CK_ULONG ulParameterLen;
|
|
61 |
* } CK_MECHANISM;
|
|
62 |
* </PRE>
|
|
63 |
*
|
|
64 |
* @author Karl Scheibelhofer <Karl.Scheibelhofer@iaik.at>
|
|
65 |
* @author Martin Schlaeffer <schlaeff@sbox.tugraz.at>
|
|
66 |
*/
|
|
67 |
public class CK_MECHANISM {
|
|
68 |
|
|
69 |
/**
|
|
70 |
* <B>PKCS#11:</B>
|
|
71 |
* <PRE>
|
|
72 |
* CK_MECHANISM_TYPE mechanism;
|
|
73 |
* </PRE>
|
|
74 |
*/
|
|
75 |
public long mechanism;
|
|
76 |
|
|
77 |
/**
|
|
78 |
* <B>PKCS#11:</B>
|
|
79 |
* <PRE>
|
|
80 |
* CK_VOID_PTR pParameter;
|
|
81 |
* CK_ULONG ulParameterLen;
|
|
82 |
* </PRE>
|
|
83 |
*/
|
|
84 |
public Object pParameter;
|
|
85 |
|
|
86 |
public CK_MECHANISM() {
|
|
87 |
// empty
|
|
88 |
}
|
|
89 |
|
|
90 |
public CK_MECHANISM(long mechanism) {
|
|
91 |
this.mechanism = mechanism;
|
|
92 |
}
|
|
93 |
|
|
94 |
// We don't have a (long,Object) constructor to force type checking.
|
|
95 |
// This makes sure we don't accidentally pass a class that the native
|
|
96 |
// code cannot handle.
|
|
97 |
|
|
98 |
public CK_MECHANISM(long mechanism, byte[] pParameter) {
|
|
99 |
init(mechanism, pParameter);
|
|
100 |
}
|
|
101 |
|
|
102 |
public CK_MECHANISM(long mechanism, BigInteger b) {
|
|
103 |
init(mechanism, sun.security.pkcs11.P11Util.getMagnitude(b));
|
|
104 |
}
|
|
105 |
|
|
106 |
public CK_MECHANISM(long mechanism, CK_VERSION version) {
|
|
107 |
init(mechanism, version);
|
|
108 |
}
|
|
109 |
|
|
110 |
public CK_MECHANISM(long mechanism, CK_SSL3_MASTER_KEY_DERIVE_PARAMS params) {
|
|
111 |
init(mechanism, params);
|
|
112 |
}
|
|
113 |
|
|
114 |
public CK_MECHANISM(long mechanism, CK_SSL3_KEY_MAT_PARAMS params) {
|
|
115 |
init(mechanism, params);
|
|
116 |
}
|
|
117 |
|
|
118 |
public CK_MECHANISM(long mechanism, CK_TLS_PRF_PARAMS params) {
|
|
119 |
init(mechanism, params);
|
|
120 |
}
|
|
121 |
|
|
122 |
public CK_MECHANISM(long mechanism, CK_ECDH1_DERIVE_PARAMS params) {
|
|
123 |
init(mechanism, params);
|
|
124 |
}
|
|
125 |
|
|
126 |
public CK_MECHANISM(long mechanism, Long params) {
|
|
127 |
init(mechanism, params);
|
|
128 |
}
|
|
129 |
|
|
130 |
private void init(long mechanism, Object pParameter) {
|
|
131 |
this.mechanism = mechanism;
|
|
132 |
this.pParameter = pParameter;
|
|
133 |
}
|
|
134 |
|
|
135 |
/**
|
|
136 |
* Returns the string representation of CK_MECHANISM.
|
|
137 |
*
|
|
138 |
* @return the string representation of CK_MECHANISM
|
|
139 |
*/
|
|
140 |
public String toString() {
|
|
141 |
StringBuffer buffer = new StringBuffer();
|
|
142 |
|
|
143 |
buffer.append(Constants.INDENT);
|
|
144 |
buffer.append("mechanism: ");
|
|
145 |
buffer.append(mechanism);
|
|
146 |
buffer.append(Constants.NEWLINE);
|
|
147 |
|
|
148 |
buffer.append(Constants.INDENT);
|
|
149 |
buffer.append("pParameter: ");
|
|
150 |
buffer.append(pParameter.toString());
|
|
151 |
buffer.append(Constants.NEWLINE);
|
|
152 |
|
|
153 |
buffer.append(Constants.INDENT);
|
|
154 |
buffer.append("ulParameterLen: ??");
|
|
155 |
//buffer.append(pParameter.length);
|
|
156 |
//buffer.append(Constants.NEWLINE);
|
|
157 |
|
|
158 |
return buffer.toString() ;
|
|
159 |
}
|
|
160 |
|
|
161 |
}
|