Skip to content

Commit 690d7f0

Browse files
author
Jeremy Rand
committed
Make Ctx an interface
Refs miekg#144
1 parent a4c4380 commit 690d7f0

7 files changed

+160
-90
lines changed

p11/module.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func OpenModule(path string) (Module, error) {
100100

101101
// Module represents a PKCS#11 module, and can be used to create Sessions.
102102
type Module struct {
103-
ctx *pkcs11.Ctx
103+
ctx pkcs11.Ctx
104104
}
105105

106106
// Info returns general information about the module.

p11/session.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type Session interface {
5858

5959
type sessionImpl struct {
6060
sync.Mutex
61-
ctx *pkcs11.Ctx
61+
ctx pkcs11.Ctx
6262
handle pkcs11.SessionHandle
6363
}
6464

p11/slot.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "github.com/miekg/pkcs11"
44

55
// Slot represents a slot that may hold a token.
66
type Slot struct {
7-
ctx *pkcs11.Ctx
7+
ctx pkcs11.Ctx
88
id uint
99
}
1010

parallel_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func init() {
4848
os.Setenv("SOFTHSM2_CONF", wd+"/softhsm2.conf")
4949
}
5050

51-
func initPKCS11Context(modulePath string) (*Ctx, error) {
51+
func initPKCS11Context(modulePath string) (Ctx, error) {
5252
context := New(modulePath)
5353

5454
if context == nil {
@@ -59,7 +59,7 @@ func initPKCS11Context(modulePath string) (*Ctx, error) {
5959
return context, err
6060
}
6161

62-
func getSlot(p *Ctx, label string) (uint, error) {
62+
func getSlot(p Ctx, label string) (uint, error) {
6363
slots, err := p.GetSlotList(true)
6464
if err != nil {
6565
return 0, err
@@ -80,7 +80,7 @@ func getSlot(p *Ctx, label string) (uint, error) {
8080
return 0, fmt.Errorf("Slot not found: %s", label)
8181
}
8282

83-
func getPrivateKey(context *Ctx, session SessionHandle, label string) (ObjectHandle, error) {
83+
func getPrivateKey(context Ctx, session SessionHandle, label string) (ObjectHandle, error) {
8484
var noKey ObjectHandle
8585
template := []*Attribute{
8686
NewAttribute(CKA_CLASS, CKO_PRIVATE_KEY),
@@ -105,12 +105,12 @@ func getPrivateKey(context *Ctx, session SessionHandle, label string) (ObjectHan
105105
}
106106

107107
type signer struct {
108-
context *Ctx
108+
context Ctx
109109
session SessionHandle
110110
privateKey ObjectHandle
111111
}
112112

113-
func makeSigner(context *Ctx) (*signer, error) {
113+
func makeSigner(context Ctx) (*signer, error) {
114114
slot, err := getSlot(context, tokenLabel)
115115
if err != nil {
116116
return nil, err

params_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
const notFound = 0xffffffff
1212

1313
// test whether mech is available; skip the test if it isn't
14-
func needMech(t *testing.T, p *Ctx, sh SessionHandle, mech uint) {
14+
func needMech(t *testing.T, p Ctx, sh SessionHandle, mech uint) {
1515
slots, err := p.GetSlotList(true)
1616
if err != nil {
1717
t.Fatal("GetSlotList:", err)
@@ -27,7 +27,7 @@ func needMech(t *testing.T, p *Ctx, sh SessionHandle, mech uint) {
2727
t.Skipf("skipping test; mech 0x%X not supported by softhsm", mech)
2828
}
2929

30-
func findObject(t *testing.T, p *Ctx, sh SessionHandle, class uint, label string) ObjectHandle {
30+
func findObject(t *testing.T, p Ctx, sh SessionHandle, class uint, label string) ObjectHandle {
3131
template := []*Attribute{
3232
NewAttribute(CKA_CLASS, class),
3333
NewAttribute(CKA_LABEL, label),
@@ -49,7 +49,7 @@ func findObject(t *testing.T, p *Ctx, sh SessionHandle, class uint, label string
4949
}
5050

5151
// generate a rsa key if it doesn't exist
52-
func getRSA(t *testing.T, p *Ctx, sh SessionHandle) (pub, priv ObjectHandle) {
52+
func getRSA(t *testing.T, p Ctx, sh SessionHandle) (pub, priv ObjectHandle) {
5353
pub = findObject(t, p, sh, CKO_PUBLIC_KEY, "paramstest")
5454
priv = findObject(t, p, sh, CKO_PUBLIC_KEY, "paramstest")
5555
if pub == notFound || priv == notFound {

0 commit comments

Comments
 (0)