From c6addff55123667f5fc4acaca8d697dc3048a249 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Wed, 1 Dec 2021 02:37:37 +0000 Subject: [PATCH] p11mod: Implement DestroyObject Refs https://github.com/namecoin/pkcs11mod/issues/46 --- p11mod/p11mod.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/p11mod/p11mod.go b/p11mod/p11mod.go index eb42572..6843b5a 100644 --- a/p11mod/p11mod.go +++ b/p11mod/p11mod.go @@ -314,9 +314,22 @@ func (ll *llBackend) CopyObject(sh pkcs11.SessionHandle, o pkcs11.ObjectHandle, } func (ll *llBackend) DestroyObject(sh pkcs11.SessionHandle, oh pkcs11.ObjectHandle) error { - // TODO - log.Println("p11mod DestroyObject: not implemented") - return pkcs11.Error(pkcs11.CKR_FUNCTION_NOT_SUPPORTED) + session, err := ll.getSessionByHandle(sh) + if err != nil { + return err + } + + // Handles are 1-indexed, while our slice is 0-indexed. + objectIndex := int(oh-1) + + if objectIndex < 0 || objectIndex >= len(session.objects) { + log.Printf("p11mod DestroyObject: object index invalid: requested %d, object count %d\n", objectIndex, len(session.objects)) + return pkcs11.Error(pkcs11.CKR_OBJECT_HANDLE_INVALID) + } + + object := session.objects[objectIndex] + + return object.Destroy() } func (ll *llBackend) GetObjectSize(sh pkcs11.SessionHandle, oh pkcs11.ObjectHandle) (uint, error) {