public ObjectHandle DeriveKey(Mechanism mechanism, ObjectHandle baseKeyHandle, List<ObjectAttribute> attributes)
{
if (this._disposed)
throw new ObjectDisposedException(this.GetType().FullName);
if (mechanism == null)
throw new ArgumentNullException("mechanism");
if (baseKeyHandle == null)
throw new ArgumentNullException("baseKeyHandle");
CK_MECHANISM ckMechanism = mechanism.CkMechanism;
CK_ATTRIBUTE[] template = null;
ulong templateLen = 0;
if (attributes != null)
{
template = new CK_ATTRIBUTE[attributes.Count];
for (int i = 0; i < attributes.Count; i++)
template[i] = attributes[i].CkAttribute;
templateLen = Convert.ToUInt64(attributes.Count);
}
ulong derivedKey = CK.CK_INVALID_HANDLE;
CKR rv = _p11.C_DeriveKey(_sessionId, ref ckMechanism, baseKeyHandle.ObjectId, template, templateLen, ref derivedKey);
if (rv != CKR.CKR_OK)
throw new Pkcs11Exception("C_DeriveKey", rv);
return new ObjectHandle(derivedKey);
}