Net.Pkcs11Interop.HighLevelAPI81.Session.CopyObject C# (CSharp) Method

CopyObject() public method

Copies an object, creating a new object for the copy
public CopyObject ( ObjectHandle objectHandle, List attributes ) : ObjectHandle
objectHandle ObjectHandle Handle of object to be copied
attributes List New values for any attributes of the object that can ordinarily be modified
return ObjectHandle
        public ObjectHandle CopyObject(ObjectHandle objectHandle, List<ObjectAttribute> attributes)
        {
            if (this._disposed)
                throw new ObjectDisposedException(this.GetType().FullName);

            if (objectHandle == null)
                throw new ArgumentNullException("objectHandle");

            ulong objectId = CK.CK_INVALID_HANDLE;

            CK_ATTRIBUTE[] template = null;
            ulong templateLength = 0;

            if (attributes != null)
            {
                templateLength = Convert.ToUInt64(attributes.Count);
                template = new CK_ATTRIBUTE[templateLength];
                for (int i = 0; i < Convert.ToInt32(templateLength); i++)
                    template[i] = attributes[i].CkAttribute;
            }

            CKR rv = _p11.C_CopyObject(_sessionId, objectHandle.ObjectId, template, templateLength, ref objectId);
            if (rv != CKR.CKR_OK)
                throw new Pkcs11Exception("C_CopyObject", rv);

            return new ObjectHandle(objectId);
        }