lib/Crypt/Cryptoki/Raw.xs

filter: Statementstmt 0.0% 0 / 178 Branchbran 0.0% 0 / 82 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 260 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« lib/Crypt/Cryptoki/Constant.c ↑ Summary lib/Crypt/Cryptoki/const-c.inc »
1 #define PERL_NO_GET_CONTEXT
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5 #include "ppport.h"
6 #include <dlfcn.h>
7 #include "cryptoki/cryptoki.h"
8  
9 typedef struct raw {
10 void* handle;
11 CK_FUNCTION_LIST* function_list;
12 } raw_t;
13  
14 typedef raw_t* Crypt__Cryptoki__Raw;
15  
16 0 CK_RV notify_callback(CK_SESSION_HANDLE hSession, CK_NOTIFICATION event,CK_VOID_PTR pApplication) {
17 0 warn("notify\n");
18 0 return CKR_OK;
19 }
20  
21  
22 MODULE = Crypt::Cryptoki::Raw PACKAGE = Crypt::Cryptoki::Raw
23  
24 PROTOTYPES: ENABLE
25  
26  
27 Crypt::Cryptoki::Raw
28 new( const char *class, const char *library_path )
29 CODE:
30 CK_RV (*C_GetFunctionList)();
31  
32 0 RETVAL = (raw_t*)calloc(1,sizeof(raw_t));
33 0 ▶ if (! RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (! RETVAL) { 0 0 0
34 0 croak("No memory for %s", class);
35 }
36  
37 0 RETVAL->handle = dlopen(library_path, RTLD_LAZY | RTLD_LOCAL);
38 0 ▶ if (! RETVAL->handle ) {
Branch: 1 branch
BranchTrueFalseTotal
if (! RETVAL->handle ) { 0 0 0
39 0 croak("Can not open library");
40 }
41  
42 0 C_GetFunctionList = (CK_RV (*)())dlsym(RETVAL->handle,"C_GetFunctionList");
43 0 ▶ if (C_GetFunctionList == NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
if (C_GetFunctionList == NULL ) { 0 0 0
44 0 croak("Symbol lookup failed");
45 }
46  
47 0 CK_RV rc = C_GetFunctionList(&RETVAL->function_list);
48 0 ▶ if (rc != CKR_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rc != CKR_OK) { 0 0 0
49 0 croak("Call to C_GetFunctionList failed");
50 }
51 OUTPUT:
52 RETVAL
53  
54  
55  
56 void
57 DESTROY(self)
58 Crypt::Cryptoki::Raw self
59 CODE:
60 0 ▶ if (dlclose(self->handle)) {
Branch: 1 branch
BranchTrueFalseTotal
if (dlclose(self->handle)) { 0 0 0
61 0 warn("dlclose problem");
62 };
63 0 free(self);
64  
65  
66  
67 CK_RV
68 C_Initialize(self)
69 Crypt::Cryptoki::Raw self
70 CODE:
71 0 RETVAL = self->function_list->C_Initialize(NULL);
72 OUTPUT:
73 RETVAL
74  
75  
76 CK_RV
77 C_GetInfo(self,info)
78 Crypt::Cryptoki::Raw self
79 HV* info
80 CODE:
81 CK_INFO _info;
82 0 RETVAL = self->function_list->C_GetInfo(&_info);
83 0 ▶ if (RETVAL == CKR_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL == CKR_OK) { 0 0 0
84 0 hv_store(info, "cryptokiVersion", 15,
85 newSVpvf("%d.%d",_info.cryptokiVersion.major,_info.cryptokiVersion.minor), 0);
86 0 hv_store(info, "manufacturerID", 14, newSVpv((char*)_info.manufacturerID,32), 0);
87 0 hv_store(info, "flags", 5, newSViv(_info.flags), 0);
88 0 hv_store(info, "libraryDescription", 18, newSVpv((char*)_info.libraryDescription,32), 0);
89 0 hv_store(info, "libraryVersion", 14,
90 newSVpvf("%d.%d",_info.libraryVersion.major,_info.libraryVersion.minor),0);
91 }
92 OUTPUT:
93 RETVAL
94 info
95  
96  
97 CK_RV
98 C_GetSlotList(self,tokenPresent,pSlotList)
99 Crypt::Cryptoki::Raw self
100 CK_BBOOL tokenPresent
101 AV* pSlotList
102 CODE:
103 CK_ULONG pulCount;
104  
105 0 RETVAL = self->function_list->C_GetSlotList(tokenPresent,NULL_PTR,&pulCount);
106  
107 0 ▶ if ( RETVAL == CKR_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL == CKR_OK ) { 0 0 0
108 CK_SLOT_ID_PTR _pSlotList;
109 0 ▶ Newxz(_pSlotList, pulCount, CK_SLOT_ID);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(_pSlotList, pulCount, CK_SLOT_ID); 0 0 0
110  
111 0 RETVAL = self->function_list->C_GetSlotList(tokenPresent,_pSlotList,&pulCount);
112  
113 0 ▶ if ( RETVAL == CKR_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL == CKR_OK ) { 0 0 0
114 0 unsigned int i = 0;
115 0 ▶ for(i=0;i<pulCount;i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=0;i<pulCount;i++) { 0 0 0
116 0 av_push((AV*)pSlotList,newSViv(_pSlotList[i]));
117 }
118 }
119  
120 0 Safefree(_pSlotList);
121 }
122 OUTPUT:
123 RETVAL
124 pSlotList
125  
126  
127 CK_RV
128 C_GetSlotInfo(self,slotID,pInfo)
129 Crypt::Cryptoki::Raw self
130 CK_SLOT_ID slotID
131 HV* pInfo
132 CODE:
133 CK_SLOT_INFO _pInfo;
134 0 RETVAL = self->function_list->C_GetSlotInfo(slotID,&_pInfo);
135 0 ▶ if (RETVAL == CKR_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL == CKR_OK) { 0 0 0
136 0 hv_store(pInfo, "slotDescription", 15, newSVpv((char*)_pInfo.slotDescription,64), 0);
137 0 hv_store(pInfo, "manufacturerID", 14, newSVpv((char*)_pInfo.manufacturerID,32), 0);
138 0 hv_store(pInfo, "flags", 5, newSViv(_pInfo.flags), 0);
139 0 hv_store(pInfo, "hardwareVersion", 15,
140 newSVpvf("%d.%d",_pInfo.hardwareVersion.major,_pInfo.hardwareVersion.minor), 0);
141 0 hv_store(pInfo, "firmwareVersion", 15,
142 newSVpvf("%d.%d",_pInfo.firmwareVersion.major,_pInfo.firmwareVersion.minor), 0);
143 }
144 OUTPUT:
145 RETVAL
146 pInfo
147  
148  
149  
150 CK_RV
151 C_GetTokenInfo(self,slotID,pInfo)
152 Crypt::Cryptoki::Raw self
153 CK_SLOT_ID slotID
154 HV* pInfo
155 CODE:
156 CK_TOKEN_INFO _pInfo;
157 0 RETVAL = self->function_list->C_GetTokenInfo(slotID,&_pInfo);
158 0 ▶ if (RETVAL == CKR_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL == CKR_OK) { 0 0 0
159 0 hv_store(pInfo, "label", 5, newSVpv((char*)_pInfo.label,32), 0);
160 0 hv_store(pInfo, "manufacturerID", 14, newSVpv((char*)_pInfo.manufacturerID,32), 0);
161 0 hv_store(pInfo, "model", 5, newSVpv((char*)_pInfo.model,16), 0);
162 0 hv_store(pInfo, "serialNumber", 12, newSVpv((char*)_pInfo.serialNumber,16), 0);
163 0 hv_store(pInfo, "flags", 5, newSViv(_pInfo.flags), 0);
164 0 hv_store(pInfo, "ulMaxSessionCount", 17, newSVuv(_pInfo.ulMaxSessionCount), 0);
165 0 hv_store(pInfo, "ulSessionCount", 14, newSVuv(_pInfo.ulSessionCount), 0);
166 0 hv_store(pInfo, "ulMaxRwSessionCount", 19, newSVuv(_pInfo.ulMaxRwSessionCount), 0);
167 0 hv_store(pInfo, "ulRwSessionCount", 16, newSVuv(_pInfo.ulRwSessionCount), 0);
168 0 hv_store(pInfo, "ulMaxPinLen", 11, newSVuv(_pInfo.ulMaxPinLen), 0);
169 0 hv_store(pInfo, "ulMinPinLen", 11, newSVuv(_pInfo.ulMinPinLen), 0);
170 0 hv_store(pInfo, "ulTotalPublicMemory", 19, newSVuv(_pInfo.ulTotalPublicMemory), 0);
171 0 hv_store(pInfo, "ulFreePublicMemory", 18, newSVuv(_pInfo.ulFreePublicMemory), 0);
172 0 hv_store(pInfo, "ulTotalPrivateMemory", 20, newSVuv(_pInfo.ulTotalPrivateMemory), 0);
173 0 hv_store(pInfo, "ulFreePrivateMemory", 19, newSVuv(_pInfo.ulFreePrivateMemory), 0);
174 0 hv_store(pInfo, "hardwareVersion", 15,
175 newSVpvf("%d.%d",_pInfo.hardwareVersion.major,_pInfo.hardwareVersion.minor), 0);
176 0 hv_store(pInfo, "firmwareVersion", 15,
177 newSVpvf("%d.%d",_pInfo.firmwareVersion.major,_pInfo.firmwareVersion.minor), 0);
178 0 hv_store(pInfo, "utcTime", 7, newSVpv((char*)_pInfo.utcTime,16), 0);
179 }
180 OUTPUT:
181 RETVAL
182 pInfo
183  
184  
185 CK_RV
186 C_OpenSession(self,slotID,flags,phSession)
187 Crypt::Cryptoki::Raw self
188 CK_SLOT_ID slotID
189 CK_FLAGS flags
190 // CK_VOID_PTR pApplication
191 // CK_NOTIFY Notify
192 CK_SESSION_HANDLE phSession
193 CODE:
194 // TODO: pass perl callback to wrapper and call it there
195 0 CK_NOTIFY Notify = &notify_callback;
196  
197 0 RETVAL = self->function_list->C_OpenSession(slotID,flags,NULL_PTR,Notify,&phSession);
198 OUTPUT:
199 RETVAL
200 phSession
201  
202  
203 CK_RV
204 C_GetSessionInfo(self,hSession,pInfo)
205 Crypt::Cryptoki::Raw self
206 CK_SESSION_HANDLE hSession
207 HV* pInfo
208 CODE:
209 CK_SESSION_INFO _pInfo;
210 0 RETVAL = self->function_list->C_GetSessionInfo(hSession,&_pInfo);
211 0 ▶ if (RETVAL == CKR_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL == CKR_OK) { 0 0 0
212 0 hv_store(pInfo, "slotID", 6, newSVuv(_pInfo.slotID), 0);
213 0 hv_store(pInfo, "state", 5, newSVuv(_pInfo.state), 0);
214 0 hv_store(pInfo, "flags", 5, newSViv(_pInfo.flags), 0);
215 0 hv_store(pInfo, "ulDeviceError", 13, newSVuv(_pInfo.ulDeviceError), 0);
216 }
217 OUTPUT:
218 RETVAL
219 pInfo
220
221  
222  
223 CK_RV
224 C_Login(self,hSession,userType,pPin)
225 Crypt::Cryptoki::Raw self
226 CK_SESSION_HANDLE hSession
227 CK_USER_TYPE userType
228 CK_UTF8CHAR_PTR pPin
229 CODE:
230 0 CK_ULONG ulPinLen = strlen((const char *)pPin);
231 0 RETVAL = self->function_list->C_Login(hSession,userType,pPin,ulPinLen);
232 OUTPUT:
233 RETVAL
234  
235  
236 CK_RV
237 C_GenerateKeyPair(self,hSession,pMechanism, \
238 pPublicKeyTemplate, \
239 pPrivateKeyTemplate, \
240 phPublicKey,phPrivateKey)
241 Crypt::Cryptoki::Raw self
242 CK_SESSION_HANDLE hSession
243 AV* pMechanism
244 AV* pPublicKeyTemplate
245 AV* pPrivateKeyTemplate
246 CK_OBJECT_HANDLE phPublicKey
247 CK_OBJECT_HANDLE phPrivateKey
248 CODE:
249 CK_MECHANISM _pMechanism;
250 CK_ATTRIBUTE_PTR _pPublicKeyTemplate;
251 0 CK_ULONG ulPublicKeyAttributeCount = 0;
252 CK_ATTRIBUTE_PTR _pPrivateKeyTemplate;
253 0 CK_ULONG ulPrivateKeyAttributeCount = 0;
254  
255 0 _pMechanism.mechanism = SvUV(*av_fetch(pMechanism, 0, 0));
256 0 _pMechanism.pParameter = NULL_PTR;
257 0 _pMechanism.ulParameterLen = 0;
258  
259 0 ▶ Newxz(_pPublicKeyTemplate, av_len(pPublicKeyTemplate)+1, CK_ATTRIBUTE);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(_pPublicKeyTemplate, av_len(pPublicKeyTemplate)+1, CK_ATTRIBUTE); 0 0 0
260 0 int i = 0;
261 0 ▶ for(i=0;i<=av_len(pPublicKeyTemplate);++i){
Branch: 1 branch
BranchTrueFalseTotal
for(i=0;i<=av_len(pPublicKeyTemplate);++i){ 0 0 0
262 0 SV** elem = av_fetch(pPublicKeyTemplate, i, 0);
263 0 ▶ if ( elem == NULL || SvTYPE(SvRV(*elem)) != SVt_PVAV ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( elem == NULL || SvTYPE(SvRV(*elem)) != SVt_PVAV ) { 0 0 0
if ( elem == NULL || SvTYPE(SvRV(*elem)) != SVt_PVAV ) { 0 0 0
264 0 croak("Error: wrong argument");
265 }
266 0 AV* attr = (AV*)SvRV(*elem);
267 0 ▶ if ( av_len(attr) != 1 ) { // 2
Branch: 1 branch
BranchTrueFalseTotal
if ( av_len(attr) != 1 ) { // 2 0 0 0
268 0 croak("Illegal array length in argument");
269 }
270  
271 0 _pPublicKeyTemplate[i].type = SvUV(*av_fetch(attr, 0, 0));
272  
273 0 SV* _value = *av_fetch(attr, 1, 0);
274 0 CK_ULONG _len = sv_len(_value);
275  
276 0 _pPublicKeyTemplate[i].pValue = (void*)SvPV(_value, _len);
277 0 _pPublicKeyTemplate[i].ulValueLen = _len;
278  
279 0 ulPublicKeyAttributeCount++;
280 }
281  
282 0 ▶ Newxz(_pPrivateKeyTemplate, av_len(pPrivateKeyTemplate)+1, CK_ATTRIBUTE);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(_pPrivateKeyTemplate, av_len(pPrivateKeyTemplate)+1, CK_ATTRIBUTE); 0 0 0
283 0 ▶ for(i=0;i<=av_len(pPrivateKeyTemplate);++i){
Branch: 1 branch
BranchTrueFalseTotal
for(i=0;i<=av_len(pPrivateKeyTemplate);++i){ 0 0 0
284 0 SV** elem = av_fetch(pPrivateKeyTemplate, i, 0);
285 0 ▶ if ( elem == NULL || SvTYPE(SvRV(*elem)) != SVt_PVAV ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( elem == NULL || SvTYPE(SvRV(*elem)) != SVt_PVAV ) { 0 0 0
if ( elem == NULL || SvTYPE(SvRV(*elem)) != SVt_PVAV ) { 0 0 0
286 0 croak("Error: wrong argument");
287 }
288 0 AV* attr = (AV*)SvRV(*elem);
289 0 ▶ if ( av_len(attr) != 1 ) { // 2
Branch: 1 branch
BranchTrueFalseTotal
if ( av_len(attr) != 1 ) { // 2 0 0 0
290 0 croak("Illegal array length in argument");
291 }
292  
293 0 _pPrivateKeyTemplate[i].type = SvUV(*av_fetch(attr, 0, 0));
294  
295 0 SV* _value = *av_fetch(attr, 1, 0);
296 0 CK_ULONG _len = sv_len(_value);
297  
298 0 _pPrivateKeyTemplate[i].pValue = (void*)SvPV(_value, _len);
299 0 _pPrivateKeyTemplate[i].ulValueLen = _len;
300  
301 0 ulPrivateKeyAttributeCount++;
302 }
303  
304 0 RETVAL = self->function_list->C_GenerateKeyPair(hSession,&_pMechanism,
305 _pPublicKeyTemplate,ulPublicKeyAttributeCount,
306 _pPrivateKeyTemplate,ulPrivateKeyAttributeCount,
307 &phPublicKey,&phPrivateKey);
308  
309 0 Safefree(_pPublicKeyTemplate);
310 0 Safefree(_pPrivateKeyTemplate);
311 OUTPUT:
312 RETVAL
313 phPublicKey
314 phPrivateKey
315  
316  
317  
318 CK_RV
319 C_EncryptInit(self,hSession,pMechanism,hKey)
320 Crypt::Cryptoki::Raw self
321 CK_SESSION_HANDLE hSession
322 AV* pMechanism
323 CK_OBJECT_HANDLE hKey
324 CODE:
325 CK_MECHANISM _pMechanism;
326 0 _pMechanism.mechanism = SvUV(*av_fetch(pMechanism, 0, 0));
327 0 _pMechanism.pParameter = NULL_PTR;
328 0 _pMechanism.ulParameterLen = 0;
329 0 RETVAL = self->function_list->C_EncryptInit(hSession,&_pMechanism,hKey);
330 OUTPUT:
331 RETVAL
332  
333  
334  
335  
336 CK_RV
337 C_Encrypt(self,hSession,pData,ulDataLen,pEncryptedData,ulEncryptedDataLen)
338 Crypt::Cryptoki::Raw self
339 CK_SESSION_HANDLE hSession
340 char* pData
341 CK_ULONG ulDataLen
342 SV* pEncryptedData
343 CK_ULONG ulEncryptedDataLen
344 CODE:
345 0 RETVAL = self->function_list->C_Encrypt(hSession,(CK_BYTE_PTR)pData,ulDataLen,
346 NULL_PTR,&ulEncryptedDataLen);
347 0 ▶ if ( RETVAL==CKR_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL==CKR_OK ) { 0 0 0
348 CK_BYTE_PTR _pEncryptedData;
349 0 Newx(_pEncryptedData,ulEncryptedDataLen,CK_BYTE);
350 0 RETVAL = self->function_list->C_Encrypt(hSession,(CK_BYTE_PTR)pData,ulDataLen,
351 _pEncryptedData,&ulEncryptedDataLen);
352  
353 0 ▶ if ( RETVAL==CKR_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL==CKR_OK ) { 0 0 0
354 0 *pEncryptedData = *newSVpv((char*)_pEncryptedData,ulEncryptedDataLen);
355 }
356 }
357 OUTPUT:
358 RETVAL
359 pEncryptedData
360 ulEncryptedDataLen
361  
362  
363  
364  
365 CK_RV
366 C_EncryptUpdate(self,hSession,pPart,ulPartLen,pEncryptedPart,ulEncryptedPartLen)
367 Crypt::Cryptoki::Raw self
368 CK_SESSION_HANDLE hSession
369 char* pPart
370 CK_ULONG ulPartLen
371 SV* pEncryptedPart
372 CK_ULONG ulEncryptedPartLen
373 CODE:
374 CK_BYTE_PTR _pEncryptedPart;
375 0 Newx(_pEncryptedPart,ulEncryptedPartLen,CK_BYTE);
376  
377 0 RETVAL = self->function_list->C_EncryptUpdate(
378 hSession,(CK_BYTE_PTR)pPart,ulPartLen,_pEncryptedPart,&ulEncryptedPartLen
379 );
380
381 0 ▶ if ( RETVAL==CKR_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL==CKR_OK ) { 0 0 0
382 0 *pEncryptedPart = *newSVpv((char*)_pEncryptedPart,ulEncryptedPartLen);
383 }
384 OUTPUT:
385 RETVAL
386 pEncryptedPart
387 ulEncryptedPartLen
388  
389  
390  
391 CK_RV
392 C_EncryptFinal(self,hSession,pEncryptedPart,ulEncryptedPartLen)
393 Crypt::Cryptoki::Raw self
394 CK_SESSION_HANDLE hSession
395 SV* pEncryptedPart
396 CK_ULONG ulEncryptedPartLen
397 CODE:
398 CK_BYTE_PTR _pEncryptedPart;
399 0 Newx(_pEncryptedPart,ulEncryptedPartLen,CK_BYTE);
400  
401 0 RETVAL = self->function_list->C_EncryptFinal(
402 hSession,_pEncryptedPart,&ulEncryptedPartLen
403 );
404
405 0 ▶ if ( RETVAL==CKR_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL==CKR_OK ) { 0 0 0
406 0 *pEncryptedPart = *newSVpv((char*)_pEncryptedPart,ulEncryptedPartLen);
407 }
408 OUTPUT:
409 RETVAL
410 pEncryptedPart
411 ulEncryptedPartLen
412  
413  
414  
415  
416  
417 CK_RV
418 C_DecryptInit(self,hSession,pMechanism,hKey)
419 Crypt::Cryptoki::Raw self
420 CK_SESSION_HANDLE hSession
421 AV* pMechanism
422 CK_OBJECT_HANDLE hKey
423 CODE:
424 CK_MECHANISM _pMechanism;
425 0 _pMechanism.mechanism = SvUV(*av_fetch(pMechanism, 0, 0));
426 0 _pMechanism.pParameter = NULL_PTR;
427 0 _pMechanism.ulParameterLen = 0;
428 0 RETVAL = self->function_list->C_DecryptInit(hSession,&_pMechanism,hKey);
429 OUTPUT:
430 RETVAL
431  
432  
433  
434 CK_RV
435 C_Decrypt(self,hSession,pEncryptedData,ulEncryptedDataLen,pData,ulDataLen)
436 Crypt::Cryptoki::Raw self
437 CK_SESSION_HANDLE hSession
438 char* pEncryptedData
439 CK_ULONG ulEncryptedDataLen
440 SV* pData
441 CK_ULONG ulDataLen
442 CODE:
443 0 RETVAL = self->function_list->C_Decrypt(hSession,(CK_BYTE_PTR)pEncryptedData,ulEncryptedDataLen,
444 NULL_PTR,&ulDataLen);
445 0 ▶ if ( RETVAL==CKR_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL==CKR_OK ) { 0 0 0
446 CK_BYTE_PTR _pData;
447 0 Newx(_pData,ulDataLen,CK_BYTE);
448 0 RETVAL = self->function_list->C_Decrypt(hSession,(CK_BYTE_PTR)pEncryptedData,ulEncryptedDataLen,
449 _pData,&ulDataLen);
450  
451 0 ▶ if ( RETVAL==CKR_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL==CKR_OK ) { 0 0 0
452 0 *pData = *newSVpv((char*)_pData, ulDataLen);
453 }
454 }
455 OUTPUT:
456 RETVAL
457 pData
458 ulDataLen
459  
460  
461  
462 CK_RV
463 C_SignInit(self,hSession,pMechanism,hKey)
464 Crypt::Cryptoki::Raw self
465 CK_SESSION_HANDLE hSession
466 AV* pMechanism
467 CK_OBJECT_HANDLE hKey
468 CODE:
469 CK_MECHANISM _pMechanism;
470 0 _pMechanism.mechanism = SvUV(*av_fetch(pMechanism, 0, 0));
471 0 _pMechanism.pParameter = NULL_PTR;
472 0 _pMechanism.ulParameterLen = 0;
473 0 RETVAL = self->function_list->C_SignInit(hSession,&_pMechanism,hKey);
474 OUTPUT:
475 RETVAL
476  
477  
478  
479 CK_RV
480 C_Sign(self,hSession,pData,ulDataLen,pSignature,ulSignatureLen)
481 Crypt::Cryptoki::Raw self
482 CK_SESSION_HANDLE hSession
483 char* pData
484 CK_ULONG ulDataLen
485 SV* pSignature
486 CK_ULONG ulSignatureLen
487 CODE:
488 0 RETVAL = self->function_list->C_Sign(hSession,(CK_BYTE_PTR)pData,ulDataLen,
489 NULL_PTR,&ulSignatureLen);
490 0 ▶ if ( RETVAL==CKR_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL==CKR_OK ) { 0 0 0
491 CK_BYTE_PTR _pSignature;
492 0 Newx(_pSignature,ulSignatureLen,CK_BYTE);
493 0 RETVAL = self->function_list->C_Sign(hSession,(CK_BYTE_PTR)pData,ulDataLen,
494 _pSignature,&ulSignatureLen);
495  
496 0 ▶ if ( RETVAL==CKR_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL==CKR_OK ) { 0 0 0
497 0 *pSignature = *newSVpv((char*)_pSignature, ulSignatureLen);
498 }
499 }
500 OUTPUT:
501 RETVAL
502 pSignature
503 ulSignatureLen
504  
505  
506  
507 CK_RV
508 C_VerifyInit(self,hSession,pMechanism,hKey)
509 Crypt::Cryptoki::Raw self
510 CK_SESSION_HANDLE hSession
511 AV* pMechanism
512 CK_OBJECT_HANDLE hKey
513 CODE:
514 CK_MECHANISM _pMechanism;
515 0 _pMechanism.mechanism = SvUV(*av_fetch(pMechanism, 0, 0));
516 0 _pMechanism.pParameter = NULL_PTR;
517 0 _pMechanism.ulParameterLen = 0;
518 0 RETVAL = self->function_list->C_VerifyInit(hSession,&_pMechanism,hKey);
519 OUTPUT:
520 RETVAL
521  
522  
523  
524 CK_RV
525 C_Verify(self,hSession,pData,ulDataLen,pSignature,ulSignatureLen)
526 Crypt::Cryptoki::Raw self
527 CK_SESSION_HANDLE hSession
528 char* pData
529 CK_ULONG ulDataLen
530 char* pSignature
531 CK_ULONG ulSignatureLen
532 CODE:
533 0 RETVAL = self->function_list->C_Verify(hSession,(CK_BYTE_PTR)pData,ulDataLen,
534 (CK_BYTE_PTR)pSignature,ulSignatureLen);
535 OUTPUT:
536 RETVAL
537  
538  
539  
540  
541 CK_RV
542 C_DestroyObject(self,hSession,hObject)
543 Crypt::Cryptoki::Raw self
544 CK_SESSION_HANDLE hSession
545 CK_OBJECT_HANDLE hObject
546 CODE:
547 0 RETVAL = self->function_list->C_DestroyObject(hSession,hObject);
548 OUTPUT:
549 RETVAL
550  
551  
552  
553  
554 CK_RV
555 C_GetAttributeValue(self,hSession,hObject,pTemplate)
556 Crypt::Cryptoki::Raw self
557 CK_SESSION_HANDLE hSession
558 CK_OBJECT_HANDLE hObject
559 AV* pTemplate
560 CODE:
561 CK_ATTRIBUTE_PTR _pTemplate;
562 0 CK_ULONG ulCount = 0;
563 0 ▶ Newxz(_pTemplate, av_len(pTemplate)+1, CK_ATTRIBUTE);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(_pTemplate, av_len(pTemplate)+1, CK_ATTRIBUTE); 0 0 0
564  
565 0 int i = 0;
566 0 ▶ for(i=0;i<=av_len(pTemplate);++i){
Branch: 1 branch
BranchTrueFalseTotal
for(i=0;i<=av_len(pTemplate);++i){ 0 0 0
567 0 SV** elem = av_fetch(pTemplate, i, 0);
568 0 ▶ if ( elem == NULL || SvTYPE(SvRV(*elem)) != SVt_PVAV ) {
Branch: 2 branches
BranchTrueFalseTotal
if ( elem == NULL || SvTYPE(SvRV(*elem)) != SVt_PVAV ) { 0 0 0
if ( elem == NULL || SvTYPE(SvRV(*elem)) != SVt_PVAV ) { 0 0 0
569 0 croak("Error: wrong argument");
570 }
571 0 AV* attr = (AV*)SvRV(*elem);
572 0 ▶ if ( av_len(attr) != 1 ) { // 2
Branch: 1 branch
BranchTrueFalseTotal
if ( av_len(attr) != 1 ) { // 2 0 0 0
573 0 croak("Illegal array length in argument");
574 }
575 0 _pTemplate[i].type = SvUV(*av_fetch(attr, 0, 0));
576
577 // TODO: special case: pValue is array of attributes
578  
579 0 _pTemplate[i].pValue = NULL;
580 0 _pTemplate[i].ulValueLen = 0;
581 0 ulCount++;
582 }
583  
584 0 RETVAL = self->function_list->C_GetAttributeValue(hSession,hObject,_pTemplate,ulCount);
585 0 ▶ if ( RETVAL == CKR_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL == CKR_OK ) { 0 0 0
586 0 ▶ for(i=0;i<ulCount;++i){
Branch: 1 branch
BranchTrueFalseTotal
for(i=0;i<ulCount;++i){ 0 0 0
587 // printf("len: %lu\n", _pTemplate[i].ulValueLen);
588 0 ▶ if ( _pTemplate[i].ulValueLen == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( _pTemplate[i].ulValueLen == -1 ) { 0 0 0
589 0 croak("Error: attribute %d",i);
590 }
591 0 Newx(_pTemplate[i].pValue,_pTemplate[i].ulValueLen,CK_BYTE);
592 }
593  
594 0 RETVAL = self->function_list->C_GetAttributeValue(hSession,hObject,_pTemplate,ulCount);
595 0 ▶ if ( RETVAL == CKR_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( RETVAL == CKR_OK ) { 0 0 0
596 0 ▶ for(i=0;i<ulCount;++i){
Branch: 1 branch
BranchTrueFalseTotal
for(i=0;i<ulCount;++i){ 0 0 0
597 0 AV* attr = (AV*)SvRV(*av_fetch(pTemplate, i, 0));
598 0 av_store(attr, 1, newSVpv(_pTemplate[i].pValue, _pTemplate[i].ulValueLen));
599 }
600 }
601 }
602 OUTPUT:
603 RETVAL
604  
605  
606  
607  
608  
« lib/Crypt/Cryptoki/Constant.c ↑ Summary lib/Crypt/Cryptoki/const-c.inc »