forked from zeromq/goczmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
certstore.go
60 lines (50 loc) · 1.42 KB
/
certstore.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
54
55
56
57
58
59
60
package goczmq
/*
#include "czmq.h"
*/
import "C"
import
// CertStore works with directories of CURVE security certificates.
// It lets you easily load stores from disk and check if a key
// is present or not. This could be done fairly easily in pure
// Go, but is included for the sake of compatibility.
"unsafe"
type CertStore struct {
zcertstoreT *C.struct__zcertstore_t
}
// NewCertStore creates a new certificate store from
// a disk directory, loading and indexing all certificates.
func NewCertStore(location string) *CertStore {
cLocation := C.CString(location)
defer C.free(unsafe.Pointer(cLocation))
return &CertStore{
zcertstoreT: C.zcertstore_new(cLocation),
}
}
// Insert inserts a certificate into the store in memory.
// Call Save directly on the cert if you wish to save it
// to disk.
func (c *CertStore) Insert(cert *Cert) {
C.zcertstore_insert(c.zcertstoreT, &cert.zcertT)
}
// Lookup looks up a certificate in the store by public key and
// returns it.
func (c *CertStore) Lookup(key string) *Cert {
cKey := C.CString(key)
defer C.free(unsafe.Pointer(cKey))
ptr := C.zcertstore_lookup(c.zcertstoreT, cKey)
if ptr == nil {
return nil
}
return &Cert{
zcertT: ptr,
}
}
// Print prints a list of certificates in the store to stdout
func (c *CertStore) Print() {
C.zcertstore_print(c.zcertstoreT)
}
// Destroy destroys Cert instance
func (c *CertStore) Destroy() {
C.zcertstore_destroy(&c.zcertstoreT)
}