pkcs11 0.2.0-x86-mingw32 → 0.2.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,229 +1,205 @@
1
- #include "pk11.h"
2
-
3
- #define PKCS11_DEFINE_CONST(constant) \
4
- rb_define_const(cPKCS11, #constant, INT2NUM(constant))
5
-
6
- #define PKCS11_DEFINE_CONST_GROUP(group, name, value) \
7
- do { \
8
- VALUE rvalue = ULONG2NUM(value); \
9
- rb_define_const(cPKCS11, name, rvalue); \
10
- VALUE str = rb_obj_freeze(rb_str_new2(name)); \
11
- VALUE old = rb_hash_aref(group, rvalue); \
12
- if (!NIL_P(old)) rb_warning("%s is equal to %s", RSTRING_PTR(old), name); \
13
- rb_hash_aset(group, rvalue, str); \
14
- } while(0)
15
-
16
- #define PKCS11_DEFINE_OBJECT_CLASS(constant) \
17
- PKCS11_DEFINE_CONST_GROUP(vOBJECT_CLASSES, #constant, constant)
18
- #define PKCS11_DEFINE_ATTRIBUTE(constant) \
19
- PKCS11_DEFINE_CONST_GROUP(vATTRIBUTES, #constant, constant)
20
- #define PKCS11_DEFINE_MECHANISM(constant) \
21
- PKCS11_DEFINE_CONST_GROUP(vMECHANISMS, #constant, constant)
22
- #define PKCS11_DEFINE_RETURN_VALUE(constant) \
23
- do { \
24
- VALUE eError = rb_define_class_under(cPKCS11, #constant, ePKCS11Error); \
25
- VALUE rvalue = ULONG2NUM(constant); \
26
- VALUE old = rb_hash_aref(vRETURN_VALUES, rvalue); \
27
- if (!NIL_P(old)) rb_warning("%s is equal to %s", RSTRING_PTR(old), #constant); \
28
- rb_hash_aset(vRETURN_VALUES, rvalue, eError); \
29
- } while(0)
30
-
31
- static VALUE vOBJECT_CLASSES;
32
- static VALUE vATTRIBUTES;
33
- static VALUE vMECHANISMS;
34
- static VALUE vRETURN_VALUES;
35
-
36
- VALUE
37
- pkcs11_return_value_to_class(CK_RV rv, VALUE ePKCS11Error)
38
- {
39
- VALUE class;
40
-
41
- class = rb_hash_aref(vRETURN_VALUES, INT2NUM(rv));
42
- if (NIL_P(class)){
43
- class = ePKCS11Error;
44
- }
45
-
46
- return class;
47
- }
48
-
49
- void
50
- Init_pkcs11_const(VALUE cPKCS11, VALUE ePKCS11Error)
51
- {
52
- PKCS11_DEFINE_CONST(CRYPTOKI_VERSION_MAJOR);
53
- PKCS11_DEFINE_CONST(CRYPTOKI_VERSION_MINOR);
54
- PKCS11_DEFINE_CONST(CRYPTOKI_VERSION_AMENDMENT);
55
-
56
- /* General constant */
57
- PKCS11_DEFINE_CONST(CK_UNAVAILABLE_INFORMATION);
58
- PKCS11_DEFINE_CONST(CK_EFFECTIVELY_INFINITE);
59
- PKCS11_DEFINE_CONST(CK_INVALID_HANDLE);
60
-
61
- /* Notification */
62
- PKCS11_DEFINE_CONST(CKN_SURRENDER);
63
-
64
- /* Bit flag */
65
- PKCS11_DEFINE_CONST(CKF_TOKEN_PRESENT);
66
- PKCS11_DEFINE_CONST(CKF_REMOVABLE_DEVICE);
67
- PKCS11_DEFINE_CONST(CKF_HW_SLOT);
68
- PKCS11_DEFINE_CONST(CKF_RNG);
69
- PKCS11_DEFINE_CONST(CKF_WRITE_PROTECTED);
70
- PKCS11_DEFINE_CONST(CKF_LOGIN_REQUIRED);
71
- PKCS11_DEFINE_CONST(CKF_USER_PIN_INITIALIZED);
72
- PKCS11_DEFINE_CONST(CKF_RESTORE_KEY_NOT_NEEDED);
73
- PKCS11_DEFINE_CONST(CKF_CLOCK_ON_TOKEN);
74
- PKCS11_DEFINE_CONST(CKF_PROTECTED_AUTHENTICATION_PATH);
75
- PKCS11_DEFINE_CONST(CKF_DUAL_CRYPTO_OPERATIONS);
76
- PKCS11_DEFINE_CONST(CKF_TOKEN_INITIALIZED);
77
- PKCS11_DEFINE_CONST(CKF_SECONDARY_AUTHENTICATION);
78
- PKCS11_DEFINE_CONST(CKF_USER_PIN_COUNT_LOW);
79
- PKCS11_DEFINE_CONST(CKF_USER_PIN_FINAL_TRY);
80
- PKCS11_DEFINE_CONST(CKF_USER_PIN_LOCKED);
81
- PKCS11_DEFINE_CONST(CKF_USER_PIN_TO_BE_CHANGED);
82
- PKCS11_DEFINE_CONST(CKF_SO_PIN_COUNT_LOW);
83
- PKCS11_DEFINE_CONST(CKF_SO_PIN_FINAL_TRY);
84
- PKCS11_DEFINE_CONST(CKF_SO_PIN_LOCKED);
85
- PKCS11_DEFINE_CONST(CKF_SO_PIN_TO_BE_CHANGED);
86
- PKCS11_DEFINE_CONST(CKF_RW_SESSION);
87
- PKCS11_DEFINE_CONST(CKF_SERIAL_SESSION);
88
- PKCS11_DEFINE_CONST(CKF_LIBRARY_CANT_CREATE_OS_THREADS);
89
- PKCS11_DEFINE_CONST(CKF_OS_LOCKING_OK);
90
- PKCS11_DEFINE_CONST(CKF_DONT_BLOCK);
91
- PKCS11_DEFINE_CONST(CKF_HW);
92
- PKCS11_DEFINE_CONST(CKF_ENCRYPT);
93
- PKCS11_DEFINE_CONST(CKF_DECRYPT);
94
- PKCS11_DEFINE_CONST(CKF_DIGEST);
95
- PKCS11_DEFINE_CONST(CKF_SIGN);
96
- PKCS11_DEFINE_CONST(CKF_SIGN_RECOVER);
97
- PKCS11_DEFINE_CONST(CKF_VERIFY);
98
- PKCS11_DEFINE_CONST(CKF_VERIFY_RECOVER);
99
- PKCS11_DEFINE_CONST(CKF_GENERATE);
100
- PKCS11_DEFINE_CONST(CKF_GENERATE_KEY_PAIR);
101
- PKCS11_DEFINE_CONST(CKF_WRAP);
102
- PKCS11_DEFINE_CONST(CKF_UNWRAP);
103
- PKCS11_DEFINE_CONST(CKF_DERIVE);
104
- PKCS11_DEFINE_CONST(CKF_EC_F_P);
105
- PKCS11_DEFINE_CONST(CKF_EC_F_2M);
106
- PKCS11_DEFINE_CONST(CKF_EC_ECPARAMETERS);
107
- PKCS11_DEFINE_CONST(CKF_EC_NAMEDCURVE);
108
- PKCS11_DEFINE_CONST(CKF_EC_UNCOMPRESS);
109
- PKCS11_DEFINE_CONST(CKF_EC_COMPRESS);
110
- PKCS11_DEFINE_CONST(CKF_EXTENSION);
111
- PKCS11_DEFINE_CONST(CKF_ARRAY_ATTRIBUTE);
112
- PKCS11_DEFINE_CONST(CKF_EXCLUDE_CHALLENGE);
113
- PKCS11_DEFINE_CONST(CKF_EXCLUDE_COUNTER);
114
- PKCS11_DEFINE_CONST(CKF_EXCLUDE_PIN);
115
- PKCS11_DEFINE_CONST(CKF_EXCLUDE_TIME);
116
- PKCS11_DEFINE_CONST(CKF_NEXT_OTP);
117
- PKCS11_DEFINE_CONST(CKF_USER_FRIENDLY_OTP);
118
-
119
- /* User type */
120
- PKCS11_DEFINE_CONST(CKU_SO);
121
- PKCS11_DEFINE_CONST(CKU_USER);
122
- PKCS11_DEFINE_CONST(CKU_CONTEXT_SPECIFIC);
123
-
124
- /* Hardware feature type */
125
- PKCS11_DEFINE_CONST(CKH_MONOTONIC_COUNTER);
126
- PKCS11_DEFINE_CONST(CKH_CLOCK);
127
- PKCS11_DEFINE_CONST(CKH_USER_INTERFACE);
128
- PKCS11_DEFINE_CONST(CKH_VENDOR_DEFINED);
129
-
130
- /* Key type */
131
- PKCS11_DEFINE_CONST(CKK_RSA);
132
- PKCS11_DEFINE_CONST(CKK_DSA);
133
- PKCS11_DEFINE_CONST(CKK_DH);
134
- PKCS11_DEFINE_CONST(CKK_ECDSA);
135
- PKCS11_DEFINE_CONST(CKK_EC);
136
- PKCS11_DEFINE_CONST(CKK_X9_42_DH);
137
- PKCS11_DEFINE_CONST(CKK_KEA);
138
- PKCS11_DEFINE_CONST(CKK_GENERIC_SECRET);
139
- PKCS11_DEFINE_CONST(CKK_RC2);
140
- PKCS11_DEFINE_CONST(CKK_RC4);
141
- PKCS11_DEFINE_CONST(CKK_DES);
142
- PKCS11_DEFINE_CONST(CKK_DES2);
143
- PKCS11_DEFINE_CONST(CKK_DES3);
144
- PKCS11_DEFINE_CONST(CKK_CAST);
145
- PKCS11_DEFINE_CONST(CKK_CAST3);
146
- PKCS11_DEFINE_CONST(CKK_CAST5);
147
- PKCS11_DEFINE_CONST(CKK_CAST128);
148
- PKCS11_DEFINE_CONST(CKK_RC5);
149
- PKCS11_DEFINE_CONST(CKK_IDEA);
150
- PKCS11_DEFINE_CONST(CKK_SKIPJACK);
151
- PKCS11_DEFINE_CONST(CKK_BATON);
152
- PKCS11_DEFINE_CONST(CKK_JUNIPER);
153
- PKCS11_DEFINE_CONST(CKK_CDMF);
154
- PKCS11_DEFINE_CONST(CKK_AES);
155
- PKCS11_DEFINE_CONST(CKK_ACTI);
156
- PKCS11_DEFINE_CONST(CKK_ARIA);
157
- PKCS11_DEFINE_CONST(CKK_BLOWFISH);
158
- PKCS11_DEFINE_CONST(CKK_CAMELLIA);
159
- PKCS11_DEFINE_CONST(CKK_HOTP);
160
- PKCS11_DEFINE_CONST(CKK_SECURID);
161
- PKCS11_DEFINE_CONST(CKK_TWOFISH);
162
- PKCS11_DEFINE_CONST(CKK_VENDOR_DEFINED);
163
-
164
- /* Certificate type */
165
- PKCS11_DEFINE_CONST(CKC_X_509);
166
- PKCS11_DEFINE_CONST(CKC_X_509_ATTR_CERT);
167
- PKCS11_DEFINE_CONST(CKC_WTLS);
168
- PKCS11_DEFINE_CONST(CKC_VENDOR_DEFINED);
169
-
170
- /* Session state */
171
- PKCS11_DEFINE_CONST(CKS_RO_PUBLIC_SESSION);
172
- PKCS11_DEFINE_CONST(CKS_RO_USER_FUNCTIONS);
173
- PKCS11_DEFINE_CONST(CKS_RW_PUBLIC_SESSION);
174
- PKCS11_DEFINE_CONST(CKS_RW_USER_FUNCTIONS);
175
- PKCS11_DEFINE_CONST(CKS_RW_SO_FUNCTIONS);
176
-
177
- /* Mask generation function */
178
- PKCS11_DEFINE_CONST(CKG_MGF1_SHA1);
179
- PKCS11_DEFINE_CONST(CKG_MGF1_SHA224);
180
- PKCS11_DEFINE_CONST(CKG_MGF1_SHA256);
181
- PKCS11_DEFINE_CONST(CKG_MGF1_SHA384);
182
- PKCS11_DEFINE_CONST(CKG_MGF1_SHA512);
183
-
184
- /* Key delivation function */
185
- PKCS11_DEFINE_CONST(CKD_NULL);
186
- PKCS11_DEFINE_CONST(CKD_SHA1_KDF);
187
- PKCS11_DEFINE_CONST(CKD_SHA1_KDF_ASN1);
188
- PKCS11_DEFINE_CONST(CKD_SHA1_KDF_CONCATENATE);
189
-
190
- /* Pseudo-random function */
191
- PKCS11_DEFINE_CONST(CKP_PKCS5_PBKD2_HMAC_SHA1);
192
-
193
- /* Salt/Encoding parameter store */
194
- PKCS11_DEFINE_CONST(CKZ_DATA_SPECIFIED);
195
- PKCS11_DEFINE_CONST(CKZ_SALT_SPECIFIED);
196
-
197
- vOBJECT_CLASSES = rb_hash_new();
198
- vATTRIBUTES = rb_hash_new();
199
- vMECHANISMS = rb_hash_new();
200
- vRETURN_VALUES = rb_hash_new();
201
- rb_define_const(cPKCS11, "OBJECT_CLASSES", vOBJECT_CLASSES);
202
- rb_define_const(cPKCS11, "ATTRIBUTES", vATTRIBUTES);
203
- rb_define_const(cPKCS11, "MECHANISMS", vMECHANISMS);
204
- rb_define_const(cPKCS11, "RETURN_VALUES", vRETURN_VALUES);
205
-
206
- #include "pk11_const_def.inc"
207
-
208
- rb_obj_freeze(vOBJECT_CLASSES);
209
- rb_obj_freeze(vATTRIBUTES);
210
- rb_obj_freeze(vMECHANISMS);
211
- rb_obj_freeze(vRETURN_VALUES);
212
-
213
- /* OTP parameters */
214
- PKCS11_DEFINE_CONST(CK_OTP_CHALLENGE);
215
- PKCS11_DEFINE_CONST(CK_OTP_COUNTER);
216
- PKCS11_DEFINE_CONST(CK_OTP_FLAGS);
217
- PKCS11_DEFINE_CONST(CK_OTP_FORMAT_ALPHANUMERIC);
218
- PKCS11_DEFINE_CONST(CK_OTP_FORMAT_BINARY);
219
- PKCS11_DEFINE_CONST(CK_OTP_FORMAT_DECIMAL);
220
- PKCS11_DEFINE_CONST(CK_OTP_FORMAT_HEXADECIMAL);
221
- PKCS11_DEFINE_CONST(CK_OTP_OUTPUT_FORMAT);
222
- PKCS11_DEFINE_CONST(CK_OTP_OUTPUT_LENGTH);
223
- PKCS11_DEFINE_CONST(CK_OTP_PARAM_IGNORED);
224
- PKCS11_DEFINE_CONST(CK_OTP_PARAM_MANDATORY);
225
- PKCS11_DEFINE_CONST(CK_OTP_PARAM_OPTIONAL);
226
- PKCS11_DEFINE_CONST(CK_OTP_PIN);
227
- PKCS11_DEFINE_CONST(CK_OTP_TIME);
228
- PKCS11_DEFINE_CONST(CK_OTP_VALUE);
229
- }
1
+ #include "pk11.h"
2
+ #include "pk11_const_macros.h"
3
+
4
+ #define MODULE_FOR_CONSTS cPKCS11
5
+ #define BASECLASS_FOR_ERRORS ePKCS11Error
6
+
7
+ static VALUE vOBJECT_CLASSES;
8
+ static VALUE vATTRIBUTES;
9
+ static VALUE vMECHANISMS;
10
+ static VALUE vRETURN_VALUES;
11
+
12
+ VALUE
13
+ pkcs11_return_value_to_class(CK_RV rv, VALUE ePKCS11Error)
14
+ {
15
+ VALUE class;
16
+
17
+ class = rb_hash_aref(vRETURN_VALUES, INT2NUM(rv));
18
+ if (NIL_P(class)){
19
+ class = ePKCS11Error;
20
+ }
21
+
22
+ return class;
23
+ }
24
+
25
+ void
26
+ Init_pkcs11_const(VALUE cPKCS11, VALUE ePKCS11Error)
27
+ {
28
+ PKCS11_DEFINE_CONST(CRYPTOKI_VERSION_MAJOR);
29
+ PKCS11_DEFINE_CONST(CRYPTOKI_VERSION_MINOR);
30
+ PKCS11_DEFINE_CONST(CRYPTOKI_VERSION_AMENDMENT);
31
+
32
+ /* General constant */
33
+ PKCS11_DEFINE_CONST(CK_UNAVAILABLE_INFORMATION);
34
+ PKCS11_DEFINE_CONST(CK_EFFECTIVELY_INFINITE);
35
+ PKCS11_DEFINE_CONST(CK_INVALID_HANDLE);
36
+
37
+ /* Notification */
38
+ PKCS11_DEFINE_CONST(CKN_SURRENDER);
39
+
40
+ /* Bit flag */
41
+ PKCS11_DEFINE_CONST(CKF_TOKEN_PRESENT);
42
+ PKCS11_DEFINE_CONST(CKF_REMOVABLE_DEVICE);
43
+ PKCS11_DEFINE_CONST(CKF_HW_SLOT);
44
+ PKCS11_DEFINE_CONST(CKF_RNG);
45
+ PKCS11_DEFINE_CONST(CKF_WRITE_PROTECTED);
46
+ PKCS11_DEFINE_CONST(CKF_LOGIN_REQUIRED);
47
+ PKCS11_DEFINE_CONST(CKF_USER_PIN_INITIALIZED);
48
+ PKCS11_DEFINE_CONST(CKF_RESTORE_KEY_NOT_NEEDED);
49
+ PKCS11_DEFINE_CONST(CKF_CLOCK_ON_TOKEN);
50
+ PKCS11_DEFINE_CONST(CKF_PROTECTED_AUTHENTICATION_PATH);
51
+ PKCS11_DEFINE_CONST(CKF_DUAL_CRYPTO_OPERATIONS);
52
+ PKCS11_DEFINE_CONST(CKF_TOKEN_INITIALIZED);
53
+ PKCS11_DEFINE_CONST(CKF_SECONDARY_AUTHENTICATION);
54
+ PKCS11_DEFINE_CONST(CKF_USER_PIN_COUNT_LOW);
55
+ PKCS11_DEFINE_CONST(CKF_USER_PIN_FINAL_TRY);
56
+ PKCS11_DEFINE_CONST(CKF_USER_PIN_LOCKED);
57
+ PKCS11_DEFINE_CONST(CKF_USER_PIN_TO_BE_CHANGED);
58
+ PKCS11_DEFINE_CONST(CKF_SO_PIN_COUNT_LOW);
59
+ PKCS11_DEFINE_CONST(CKF_SO_PIN_FINAL_TRY);
60
+ PKCS11_DEFINE_CONST(CKF_SO_PIN_LOCKED);
61
+ PKCS11_DEFINE_CONST(CKF_SO_PIN_TO_BE_CHANGED);
62
+ PKCS11_DEFINE_CONST(CKF_RW_SESSION);
63
+ PKCS11_DEFINE_CONST(CKF_SERIAL_SESSION);
64
+ PKCS11_DEFINE_CONST(CKF_LIBRARY_CANT_CREATE_OS_THREADS);
65
+ PKCS11_DEFINE_CONST(CKF_OS_LOCKING_OK);
66
+ PKCS11_DEFINE_CONST(CKF_DONT_BLOCK);
67
+ PKCS11_DEFINE_CONST(CKF_HW);
68
+ PKCS11_DEFINE_CONST(CKF_ENCRYPT);
69
+ PKCS11_DEFINE_CONST(CKF_DECRYPT);
70
+ PKCS11_DEFINE_CONST(CKF_DIGEST);
71
+ PKCS11_DEFINE_CONST(CKF_SIGN);
72
+ PKCS11_DEFINE_CONST(CKF_SIGN_RECOVER);
73
+ PKCS11_DEFINE_CONST(CKF_VERIFY);
74
+ PKCS11_DEFINE_CONST(CKF_VERIFY_RECOVER);
75
+ PKCS11_DEFINE_CONST(CKF_GENERATE);
76
+ PKCS11_DEFINE_CONST(CKF_GENERATE_KEY_PAIR);
77
+ PKCS11_DEFINE_CONST(CKF_WRAP);
78
+ PKCS11_DEFINE_CONST(CKF_UNWRAP);
79
+ PKCS11_DEFINE_CONST(CKF_DERIVE);
80
+ PKCS11_DEFINE_CONST(CKF_EC_F_P);
81
+ PKCS11_DEFINE_CONST(CKF_EC_F_2M);
82
+ PKCS11_DEFINE_CONST(CKF_EC_ECPARAMETERS);
83
+ PKCS11_DEFINE_CONST(CKF_EC_NAMEDCURVE);
84
+ PKCS11_DEFINE_CONST(CKF_EC_UNCOMPRESS);
85
+ PKCS11_DEFINE_CONST(CKF_EC_COMPRESS);
86
+ PKCS11_DEFINE_CONST(CKF_EXTENSION);
87
+ PKCS11_DEFINE_CONST(CKF_ARRAY_ATTRIBUTE);
88
+ PKCS11_DEFINE_CONST(CKF_EXCLUDE_CHALLENGE);
89
+ PKCS11_DEFINE_CONST(CKF_EXCLUDE_COUNTER);
90
+ PKCS11_DEFINE_CONST(CKF_EXCLUDE_PIN);
91
+ PKCS11_DEFINE_CONST(CKF_EXCLUDE_TIME);
92
+ PKCS11_DEFINE_CONST(CKF_NEXT_OTP);
93
+ PKCS11_DEFINE_CONST(CKF_USER_FRIENDLY_OTP);
94
+
95
+ /* User type */
96
+ PKCS11_DEFINE_CONST(CKU_SO);
97
+ PKCS11_DEFINE_CONST(CKU_USER);
98
+ PKCS11_DEFINE_CONST(CKU_CONTEXT_SPECIFIC);
99
+
100
+ /* Hardware feature type */
101
+ PKCS11_DEFINE_CONST(CKH_MONOTONIC_COUNTER);
102
+ PKCS11_DEFINE_CONST(CKH_CLOCK);
103
+ PKCS11_DEFINE_CONST(CKH_USER_INTERFACE);
104
+ PKCS11_DEFINE_CONST(CKH_VENDOR_DEFINED);
105
+
106
+ /* Key type */
107
+ PKCS11_DEFINE_CONST(CKK_RSA);
108
+ PKCS11_DEFINE_CONST(CKK_DSA);
109
+ PKCS11_DEFINE_CONST(CKK_DH);
110
+ PKCS11_DEFINE_CONST(CKK_ECDSA);
111
+ PKCS11_DEFINE_CONST(CKK_EC);
112
+ PKCS11_DEFINE_CONST(CKK_X9_42_DH);
113
+ PKCS11_DEFINE_CONST(CKK_KEA);
114
+ PKCS11_DEFINE_CONST(CKK_GENERIC_SECRET);
115
+ PKCS11_DEFINE_CONST(CKK_RC2);
116
+ PKCS11_DEFINE_CONST(CKK_RC4);
117
+ PKCS11_DEFINE_CONST(CKK_DES);
118
+ PKCS11_DEFINE_CONST(CKK_DES2);
119
+ PKCS11_DEFINE_CONST(CKK_DES3);
120
+ PKCS11_DEFINE_CONST(CKK_CAST);
121
+ PKCS11_DEFINE_CONST(CKK_CAST3);
122
+ PKCS11_DEFINE_CONST(CKK_CAST5);
123
+ PKCS11_DEFINE_CONST(CKK_CAST128);
124
+ PKCS11_DEFINE_CONST(CKK_RC5);
125
+ PKCS11_DEFINE_CONST(CKK_IDEA);
126
+ PKCS11_DEFINE_CONST(CKK_SKIPJACK);
127
+ PKCS11_DEFINE_CONST(CKK_BATON);
128
+ PKCS11_DEFINE_CONST(CKK_JUNIPER);
129
+ PKCS11_DEFINE_CONST(CKK_CDMF);
130
+ PKCS11_DEFINE_CONST(CKK_AES);
131
+ PKCS11_DEFINE_CONST(CKK_ACTI);
132
+ PKCS11_DEFINE_CONST(CKK_ARIA);
133
+ PKCS11_DEFINE_CONST(CKK_BLOWFISH);
134
+ PKCS11_DEFINE_CONST(CKK_CAMELLIA);
135
+ PKCS11_DEFINE_CONST(CKK_HOTP);
136
+ PKCS11_DEFINE_CONST(CKK_SECURID);
137
+ PKCS11_DEFINE_CONST(CKK_TWOFISH);
138
+ PKCS11_DEFINE_CONST(CKK_VENDOR_DEFINED);
139
+
140
+ /* Certificate type */
141
+ PKCS11_DEFINE_CONST(CKC_X_509);
142
+ PKCS11_DEFINE_CONST(CKC_X_509_ATTR_CERT);
143
+ PKCS11_DEFINE_CONST(CKC_WTLS);
144
+ PKCS11_DEFINE_CONST(CKC_VENDOR_DEFINED);
145
+
146
+ /* Session state */
147
+ PKCS11_DEFINE_CONST(CKS_RO_PUBLIC_SESSION);
148
+ PKCS11_DEFINE_CONST(CKS_RO_USER_FUNCTIONS);
149
+ PKCS11_DEFINE_CONST(CKS_RW_PUBLIC_SESSION);
150
+ PKCS11_DEFINE_CONST(CKS_RW_USER_FUNCTIONS);
151
+ PKCS11_DEFINE_CONST(CKS_RW_SO_FUNCTIONS);
152
+
153
+ /* Mask generation function */
154
+ PKCS11_DEFINE_CONST(CKG_MGF1_SHA1);
155
+ PKCS11_DEFINE_CONST(CKG_MGF1_SHA224);
156
+ PKCS11_DEFINE_CONST(CKG_MGF1_SHA256);
157
+ PKCS11_DEFINE_CONST(CKG_MGF1_SHA384);
158
+ PKCS11_DEFINE_CONST(CKG_MGF1_SHA512);
159
+
160
+ /* Key delivation function */
161
+ PKCS11_DEFINE_CONST(CKD_NULL);
162
+ PKCS11_DEFINE_CONST(CKD_SHA1_KDF);
163
+ PKCS11_DEFINE_CONST(CKD_SHA1_KDF_ASN1);
164
+ PKCS11_DEFINE_CONST(CKD_SHA1_KDF_CONCATENATE);
165
+
166
+ /* Pseudo-random function */
167
+ PKCS11_DEFINE_CONST(CKP_PKCS5_PBKD2_HMAC_SHA1);
168
+
169
+ /* Salt/Encoding parameter store */
170
+ PKCS11_DEFINE_CONST(CKZ_DATA_SPECIFIED);
171
+ PKCS11_DEFINE_CONST(CKZ_SALT_SPECIFIED);
172
+
173
+ vOBJECT_CLASSES = rb_hash_new();
174
+ vATTRIBUTES = rb_hash_new();
175
+ vMECHANISMS = rb_hash_new();
176
+ vRETURN_VALUES = rb_hash_new();
177
+ rb_define_const(cPKCS11, "OBJECT_CLASSES", vOBJECT_CLASSES);
178
+ rb_define_const(cPKCS11, "ATTRIBUTES", vATTRIBUTES);
179
+ rb_define_const(cPKCS11, "MECHANISMS", vMECHANISMS);
180
+ rb_define_const(cPKCS11, "RETURN_VALUES", vRETURN_VALUES);
181
+
182
+ #include "pk11_const_def.inc"
183
+
184
+ rb_obj_freeze(vOBJECT_CLASSES);
185
+ rb_obj_freeze(vATTRIBUTES);
186
+ rb_obj_freeze(vMECHANISMS);
187
+ rb_obj_freeze(vRETURN_VALUES);
188
+
189
+ /* OTP parameters */
190
+ PKCS11_DEFINE_CONST(CK_OTP_CHALLENGE);
191
+ PKCS11_DEFINE_CONST(CK_OTP_COUNTER);
192
+ PKCS11_DEFINE_CONST(CK_OTP_FLAGS);
193
+ PKCS11_DEFINE_CONST(CK_OTP_FORMAT_ALPHANUMERIC);
194
+ PKCS11_DEFINE_CONST(CK_OTP_FORMAT_BINARY);
195
+ PKCS11_DEFINE_CONST(CK_OTP_FORMAT_DECIMAL);
196
+ PKCS11_DEFINE_CONST(CK_OTP_FORMAT_HEXADECIMAL);
197
+ PKCS11_DEFINE_CONST(CK_OTP_OUTPUT_FORMAT);
198
+ PKCS11_DEFINE_CONST(CK_OTP_OUTPUT_LENGTH);
199
+ PKCS11_DEFINE_CONST(CK_OTP_PARAM_IGNORED);
200
+ PKCS11_DEFINE_CONST(CK_OTP_PARAM_MANDATORY);
201
+ PKCS11_DEFINE_CONST(CK_OTP_PARAM_OPTIONAL);
202
+ PKCS11_DEFINE_CONST(CK_OTP_PIN);
203
+ PKCS11_DEFINE_CONST(CK_OTP_TIME);
204
+ PKCS11_DEFINE_CONST(CK_OTP_VALUE);
205
+ }
@@ -0,0 +1,37 @@
1
+ #ifndef PK11_CONST_MACROS_INCLUDED
2
+ #define PK11_CONST_MACROS_INCLUDED
3
+
4
+ /**************************************************/
5
+ /* constant definition */
6
+ /**************************************************/
7
+
8
+ #define PKCS11_DEFINE_CONST(constant) \
9
+ rb_define_const(MODULE_FOR_CONSTS, #constant, INT2NUM(constant))
10
+
11
+ #define PKCS11_DEFINE_CONST_GROUP(group, name, value) \
12
+ do { \
13
+ VALUE rvalue = ULONG2NUM(value); \
14
+ rb_define_const(MODULE_FOR_CONSTS, name, rvalue); \
15
+ VALUE str = rb_obj_freeze(rb_str_new2(name)); \
16
+ VALUE old = rb_hash_aref(group, rvalue); \
17
+ if (!NIL_P(old)) rb_warning("%s is equal to %s", RSTRING_PTR(old), name); \
18
+ rb_hash_aset(group, rvalue, str); \
19
+ } while(0)
20
+
21
+ #define PKCS11_DEFINE_OBJECT_CLASS(constant) \
22
+ PKCS11_DEFINE_CONST_GROUP(vOBJECT_CLASSES, #constant, constant)
23
+ #define PKCS11_DEFINE_ATTRIBUTE(constant) \
24
+ PKCS11_DEFINE_CONST_GROUP(vATTRIBUTES, #constant, constant)
25
+ #define PKCS11_DEFINE_MECHANISM(constant) \
26
+ PKCS11_DEFINE_CONST_GROUP(vMECHANISMS, #constant, constant)
27
+ #define PKCS11_DEFINE_RETURN_VALUE(constant) \
28
+ do { \
29
+ VALUE eError = rb_define_class_under(MODULE_FOR_CONSTS, #constant, BASECLASS_FOR_ERRORS); \
30
+ VALUE rvalue = ULONG2NUM(constant); \
31
+ VALUE old = rb_hash_aref(vRETURN_VALUES, rvalue); \
32
+ if (!NIL_P(old)) rb_warning("%s is equal to %s", RSTRING_PTR(old), #constant); \
33
+ rb_hash_aset(vRETURN_VALUES, rvalue, eError); \
34
+ } while(0)
35
+
36
+
37
+ #endif