Skip to content

Commit

Permalink
FindObjects: Remove deprecated return value
Browse files Browse the repository at this point in the history
Fixes miekg#26
  • Loading branch information
Jeremy Rand committed Nov 3, 2022
1 parent 0c4557c commit 70133e5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion p11/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (s *sessionImpl) FindObjects(template []*pkcs11.Attribute) ([]Object, error

var results []Object
for {
objectHandles, _, err := s.ctx.FindObjects(s.handle, 100)
objectHandles, err := s.ctx.FindObjects(s.handle, 100)
if err != nil {
_ = s.ctx.FindObjectsFinal(s.handle)
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func getPrivateKey(context *Ctx, session SessionHandle, label string) (ObjectHan
if err := context.FindObjectsInit(session, template); err != nil {
return noKey, err
}
objs, _, err := context.FindObjects(session, 2)
objs, err := context.FindObjects(session, 2)
if err != nil {
return noKey, err
}
Expand Down
2 changes: 1 addition & 1 deletion params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func findObject(t *testing.T, p *Ctx, sh SessionHandle, class uint, label string
if err := p.FindObjectsInit(sh, template); err != nil {
t.Fatal("FindObjectsInit:", err)
}
obj, _, err := p.FindObjects(sh, 1)
obj, err := p.FindObjects(sh, 1)
if err != nil {
t.Fatal("FindObjects:", err)
}
Expand Down
8 changes: 3 additions & 5 deletions pkcs11.go
Original file line number Diff line number Diff line change
Expand Up @@ -1121,16 +1121,14 @@ func (c *Ctx) FindObjectsInit(sh SessionHandle, temp []*Attribute) error {
// objects that match a template, obtaining additional object
// handles. Calling the function repeatedly may yield additional results until
// an empty slice is returned.
//
// The returned boolean value is deprecated and should be ignored.
func (c *Ctx) FindObjects(sh SessionHandle, max int) ([]ObjectHandle, bool, error) {
func (c *Ctx) FindObjects(sh SessionHandle, max int) ([]ObjectHandle, error) {
var (
objectList C.CK_OBJECT_HANDLE_PTR
ulCount C.CK_ULONG
)
e := C.FindObjects(c.ctx, C.CK_SESSION_HANDLE(sh), &objectList, C.CK_ULONG(max), &ulCount)
if toError(e) != nil {
return nil, false, toError(e)
return nil, toError(e)
}
l := toList(C.CK_ULONG_PTR(unsafe.Pointer(objectList)), ulCount)
// Make again a new list of the correct type.
Expand All @@ -1139,7 +1137,7 @@ func (c *Ctx) FindObjects(sh SessionHandle, max int) ([]ObjectHandle, bool, erro
for i, v := range l {
o[i] = ObjectHandle(v)
}
return o, ulCount > C.CK_ULONG(max), nil
return o, nil
}

// FindObjectsFinal finishes a search for token and session objects.
Expand Down
4 changes: 2 additions & 2 deletions pkcs11_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestFindObject(t *testing.T) {
if e := p.FindObjectsInit(session, template); e != nil {
t.Fatalf("failed to init: %s\n", e)
}
obj, _, e := p.FindObjects(session, 2)
obj, e := p.FindObjects(session, 2)
if e != nil {
t.Fatalf("failed to find: %s\n", e)
}
Expand Down Expand Up @@ -323,7 +323,7 @@ func destroyObject(t *testing.T, p *Ctx, session SessionHandle, searchToken stri
if e := p.FindObjectsInit(session, template); e != nil {
t.Fatalf("failed to init: %s\n", e)
}
obj, _, e := p.FindObjects(session, 1)
obj, e := p.FindObjects(session, 1)
if e != nil || len(obj) == 0 {
t.Fatalf("failed to find objects")
}
Expand Down

0 comments on commit 70133e5

Please sign in to comment.