-
Notifications
You must be signed in to change notification settings - Fork 0
/
close.go
53 lines (48 loc) · 1.27 KB
/
close.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
48
49
50
51
52
53
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 finalize(CK_FUNCTION_LIST_PTR fl) {
return (*fl->C_Finalize)(NULL_PTR);
}
CK_RV close_session(CK_FUNCTION_LIST_PTR fl, CK_SESSION_HANDLE hSession) {
return (*fl->C_CloseSession)(hSession);
}
CK_RV close_all_sessions(CK_FUNCTION_LIST_PTR fl, CK_ULONG slotID) {
return (*fl->C_CloseAllSessions)(slotID);
}
*/
import "C"
import "fmt"
func (m *Cryptoki) Close() error {
rv := C.finalize(m.fl)
if rv != C.CKR_OK {
// fmt.Printf("finalize: 0x%08x\n", rv)
return fmt.Errorf("finalize: 0x%08x : %s", rv, returnValues[rv])
}
if C.dlclose(m.mod) != 0 {
return fmt.Errorf("dlclose: 0x%08x : %s", rv, returnValues[rv])
}
return nil
}
func (s *Slot) Close() error {
if err := s.logout(); err != nil {
return err
}
if rv := C.close_session(s.fl, s.h); rv != C.CKR_OK {
return fmt.Errorf("CloseSession: 0x%08x : %s", rv, returnValues[rv])
}
return nil
}
func (s *Slot) CloseAll() error {
if rv := C.close_all_sessions(s.fl, C.CK_ULONG(s.id)); rv != C.CKR_OK {
return fmt.Errorf("CloseAllSession: 0x%08x : %s", rv, returnValues[rv])
}
return nil
}