public CkCmsSigParams(ObjectHandle certificateHandle, ulong? signingMechanism, ulong? digestMechanism, string contentType, byte[] requestedAttributes, byte[] requiredAttributes)
{
_lowLevelStruct.CertificateHandle = CK.CK_INVALID_HANDLE;
_lowLevelStruct.SigningMechanism = IntPtr.Zero;
_lowLevelStruct.DigestMechanism = IntPtr.Zero;
_lowLevelStruct.ContentType = IntPtr.Zero;
_lowLevelStruct.RequestedAttributes = IntPtr.Zero;
_lowLevelStruct.RequestedAttributesLen = 0;
_lowLevelStruct.RequiredAttributes = IntPtr.Zero;
_lowLevelStruct.RequiredAttributesLen = 0;
if (certificateHandle == null)
throw new ArgumentNullException("certificateHandle");
_lowLevelStruct.CertificateHandle = certificateHandle.ObjectId;
if (signingMechanism != null)
{
byte[] bytes = ConvertUtils.ULongToBytes(signingMechanism.Value);
_lowLevelStruct.SigningMechanism = UnmanagedMemory.Allocate(bytes.Length);
UnmanagedMemory.Write(_lowLevelStruct.SigningMechanism, bytes);
}
if (digestMechanism != null)
{
byte[] bytes = ConvertUtils.ULongToBytes(digestMechanism.Value);
_lowLevelStruct.DigestMechanism = UnmanagedMemory.Allocate(bytes.Length);
UnmanagedMemory.Write(_lowLevelStruct.DigestMechanism, bytes);
}
if (contentType != null)
{
byte[] bytes = ConvertUtils.Utf8StringToBytes(contentType);
Array.Resize(ref bytes, bytes.Length + 1);
bytes[bytes.Length - 1] = 0;
_lowLevelStruct.ContentType = UnmanagedMemory.Allocate(bytes.Length);
UnmanagedMemory.Write(_lowLevelStruct.ContentType, bytes);
}
if (requestedAttributes != null)
{
_lowLevelStruct.RequestedAttributes = UnmanagedMemory.Allocate(requestedAttributes.Length);
UnmanagedMemory.Write(_lowLevelStruct.RequestedAttributes, requestedAttributes);
_lowLevelStruct.RequestedAttributesLen = Convert.ToUInt64(requestedAttributes.Length);
}
if (requiredAttributes != null)
{
_lowLevelStruct.RequiredAttributes = UnmanagedMemory.Allocate(requiredAttributes.Length);
UnmanagedMemory.Write(_lowLevelStruct.RequiredAttributes, requiredAttributes);
_lowLevelStruct.RequiredAttributesLen = Convert.ToUInt64(requiredAttributes.Length);
}
}