Skip to content

Commit

Permalink
Merge #142: Add CopyObject Function #128
Browse files Browse the repository at this point in the history
2ab6dde Add CopyObject Function #128 (robertmin1)

Pull request description:

  Add CopyObject Function #128

ACKs for top commit:
  JeremyRand:
    ACK 2ab6dde

Tree-SHA512: 7fc9f2d7828da9f796f48640c530c56d2252a4e72abc874201b6bfae0be5122601834d20300b83a5e5dfc705769e6b373b357aa29c0e29cae1b87a3e9dbcdafc
  • Loading branch information
Jeremy Rand committed Oct 16, 2022
2 parents 4b352c4 + 2ab6dde commit 8bd75a2
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions p11mod/p11mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,36 @@ func (ll *llBackend) CreateObject(sh pkcs11.SessionHandle, temp []*pkcs11.Attrib
}

func (ll *llBackend) CopyObject(sh pkcs11.SessionHandle, o pkcs11.ObjectHandle, temp []*pkcs11.Attribute) (pkcs11.ObjectHandle, error) {
// TODO
log.Println("p11mod CopyObject: not implemented")
return 0, pkcs11.Error(pkcs11.CKR_FUNCTION_NOT_SUPPORTED)
session, err := ll.getSessionByHandle(sh)
if err != nil {
return 0, err
}

// Handles are 1-indexed, while our slice is 0-indexed.
objectIndex := int(o - 1)

if objectIndex < 0 || objectIndex >= len(session.objects) {
log.Printf("p11mod CopyObject: Object index invalid: requested %d, object count %d\n", objectIndex,
len(session.objects))

return 0, pkcs11.Error(pkcs11.CKR_OBJECT_HANDLE_INVALID)
}

object := session.objects[objectIndex]

objectc, err := object.Copy(temp)
if err != nil {
return 0, err
}

session.objects = append(session.objects, objectc)

// 0 is never a valid object handle, as per PKCS#11 spec. So the object
// handle of the final object is its index + 1, which is the same as the
// length of the objects slice.
resultHandle := len(session.objects)

return pkcs11.ObjectHandle(resultHandle), nil
}

func (ll *llBackend) DestroyObject(sh pkcs11.SessionHandle, oh pkcs11.ObjectHandle) error {
Expand Down

0 comments on commit 8bd75a2

Please sign in to comment.