-
Notifications
You must be signed in to change notification settings - Fork 0
/
label.go
34 lines (29 loc) · 813 Bytes
/
label.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
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"
*/
import "C"
import "unsafe"
// Returns a string value attached to an object, which can be used to
// identify or group sets of keys and certificates.
func (o Object) Label() (string, error) {
attrs := []C.CK_ATTRIBUTE{{C.CKA_LABEL, nil, 0}}
if err := o.getAttributeValue(attrs); err != nil {
return "", err
}
n := attrs[0].ulValueLen
cLabel := (*C.CK_UTF8CHAR)(C.malloc(C.ulong(n)))
defer C.free(unsafe.Pointer(cLabel))
attrs[0].pValue = C.CK_VOID_PTR(cLabel)
if err := o.getAttributeValue(attrs); err != nil {
return "", err
}
return ckGoString(cLabel, n), nil
}