-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_operation_state.go
47 lines (41 loc) · 1.26 KB
/
get_operation_state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package certex
/*
#include <stdlib.h>
#include <dlfcn.h>
#include <unistd.h>
#include <stdio.h>
#include "./headers/cryptoki.h"
#include "./headers/pkcs11def.h"
#include "./headers/pkcs11t.h"
#include "./headers/PKICertexHSM.h"
CK_RV get_operation_state(CK_FUNCTION_LIST_PTR fl, CK_SESSION_HANDLE hSession, CK_BYTE_PTR * pOperationState, CK_ULONG_PTR pulOperationStateLen) {
CK_RV rv = (*fl->C_GetOperationState)(hSession, NULL, pulOperationStateLen);
if (rv != CKR_OK) {
return rv;
}
*pOperationState = calloc(*pulOperationStateLen, sizeof(CK_BYTE));
if (*pOperationState == NULL) {
return CKR_HOST_MEMORY;
}
rv = (*fl->C_GetOperationState)(hSession, *pOperationState, pulOperationStateLen);
return rv;
}
*/
import "C"
import (
"fmt"
"unsafe"
)
// Obtains the state of the cryptographic operation in a session.
func (s *Slot) GetOperationState() ([]byte, error) {
var (
pOperationState C.CK_BYTE_PTR
ulOperationStateLen C.CK_ULONG
)
if rv := C.get_operation_state(s.fl, s.h, &pOperationState, &ulOperationStateLen); rv != C.CKR_OK {
return nil, fmt.Errorf("GetOperationState: 0x%08x : %s", rv, returnValues[rv])
}
defer C.free(unsafe.Pointer(pOperationState))
b := C.GoBytes(unsafe.Pointer(pOperationState), C.int(ulOperationStateLen))
return b, nil
}