Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic code generation #76

Merged
merged 16 commits into from
Mar 11, 2018
Merged
Prev Previous commit
Next Next commit
Use NativeLong alias in HighLevelAPI41
  • Loading branch information
jariq committed Feb 17, 2018
commit 550cbd5b40c25007faba5c5fc82cc93fee8ad8f8
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public ulong GetValueAsUlong()
throw new ObjectDisposedException(this.GetType().FullName);

if (Platform.UnmanagedLongSize == 4)
return (Platform.StructPackingSize == 0) ? _objectAttribute40.GetValueAsUint() : _objectAttribute41.GetValueAsUint();
return (Platform.StructPackingSize == 0) ? _objectAttribute40.GetValueAsUint() : _objectAttribute41.GetValueAsNativeUlong();
else
return (Platform.StructPackingSize == 0) ? _objectAttribute80.GetValueAsUlong() : _objectAttribute81.GetValueAsUlong();
}
Expand Down Expand Up @@ -792,7 +792,7 @@ public List<ulong> GetValueAsUlongList()
if (Platform.StructPackingSize == 0)
uintList = _objectAttribute40.GetValueAsUintList();
else
uintList = _objectAttribute41.GetValueAsUintList();
uintList = _objectAttribute41.GetValueAsNativeULongList();

List<ulong> ulongList = null;

Expand Down
5 changes: 3 additions & 2 deletions src/Pkcs11Interop/Pkcs11Interop/HighLevelAPI41/LibraryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.LowLevelAPI41;
using NativeULong = System.UInt32;

namespace Net.Pkcs11Interop.HighLevelAPI41
{
Expand Down Expand Up @@ -64,12 +65,12 @@ public string ManufacturerId
/// <summary>
/// Bit flags reserved for future versions
/// </summary>
private uint _flags = 0;
private NativeULong _flags = 0;

/// <summary>
/// Bit flags reserved for future versions
/// </summary>
public uint Flags
public NativeULong Flags
{
get
{
Expand Down
9 changes: 5 additions & 4 deletions src/Pkcs11Interop/Pkcs11Interop/HighLevelAPI41/Mechanism.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.LowLevelAPI41;
using NativeULong = System.UInt32;

namespace Net.Pkcs11Interop.HighLevelAPI41
{
Expand Down Expand Up @@ -57,7 +58,7 @@ internal CK_MECHANISM CkMechanism
/// <summary>
/// The type of mechanism
/// </summary>
public uint Type
public NativeULong Type
{
get
{
Expand All @@ -77,7 +78,7 @@ public uint Type
/// Creates mechanism of given type with no parameter
/// </summary>
/// <param name="type">Mechanism type</param>
public Mechanism(uint type)
public Mechanism(NativeULong type)
{
_ckMechanism = CkmUtils.CreateMechanism(type);
}
Expand All @@ -96,7 +97,7 @@ public Mechanism(CKM type)
/// </summary>
/// <param name="type">Mechanism type</param>
/// <param name="parameter">Mechanism parameter</param>
public Mechanism(uint type, byte[] parameter)
public Mechanism(NativeULong type, byte[] parameter)
{
_ckMechanism = CkmUtils.CreateMechanism(type, parameter);
}
Expand All @@ -116,7 +117,7 @@ public Mechanism(CKM type, byte[] parameter)
/// </summary>
/// <param name="type">Mechanism type</param>
/// <param name="parameter">Mechanism parameter</param>
public Mechanism(uint type, IMechanismParams parameter)
public Mechanism(NativeULong type, IMechanismParams parameter)
{
if (parameter == null)
throw new ArgumentNullException("parameter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

using Net.Pkcs11Interop.Common;
using NativeULong = System.UInt32;

namespace Net.Pkcs11Interop.HighLevelAPI41
{
Expand All @@ -31,12 +32,12 @@ public class MechanismFlags
/// <summary>
/// Bits flags specifying mechanism capabilities
/// </summary>
private uint _flags;
private NativeULong _flags;

/// <summary>
/// Bits flags specifying mechanism capabilities
/// </summary>
public uint Flags
public NativeULong Flags
{
get
{
Expand Down Expand Up @@ -272,7 +273,7 @@ public bool EcCompress
/// Initializes new instance of MechanismFlags class
/// </summary>
/// <param name="flags">Bits flags specifying mechanism capabilities</param>
internal MechanismFlags(uint flags)
internal MechanismFlags(NativeULong flags)
{
_flags = flags;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.LowLevelAPI41;
using NativeULong = System.UInt32;

namespace Net.Pkcs11Interop.HighLevelAPI41
{
Expand Down Expand Up @@ -48,12 +49,12 @@ public CKM Mechanism
/// <summary>
/// The minimum size of the key for the mechanism (whether this is measured in bits or in bytes is mechanism-dependent)
/// </summary>
private uint _minKeySize = 0;
private NativeULong _minKeySize = 0;

/// <summary>
/// The minimum size of the key for the mechanism (whether this is measured in bits or in bytes is mechanism-dependent)
/// </summary>
public uint MinKeySize
public NativeULong MinKeySize
{
get
{
Expand All @@ -64,12 +65,12 @@ public uint MinKeySize
/// <summary>
/// The maximum size of the key for the mechanism (whether this is measured in bits or in bytes is mechanism-dependent)
/// </summary>
private uint _maxKeySize = 0;
private NativeULong _maxKeySize = 0;

/// <summary>
/// The maximum size of the key for the mechanism (whether this is measured in bits or in bytes is mechanism-dependent)
/// </summary>
public uint MaxKeySize
public NativeULong MaxKeySize
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using System;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.LowLevelAPI41;
using Net.Pkcs11Interop.LowLevelAPI41.MechanismParams;

namespace Net.Pkcs11Interop.HighLevelAPI41.MechanismParams
Expand Down Expand Up @@ -63,7 +64,7 @@ public CkAesCbcEncryptDataParams(byte[] iv, byte[] data)
{
_lowLevelStruct.Data = UnmanagedMemory.Allocate(data.Length);
UnmanagedMemory.Write(_lowLevelStruct.Data, data);
_lowLevelStruct.Length = Convert.ToUInt32(data.Length);
_lowLevelStruct.Length = NativeLongUtils.ConvertFromInt32(data.Length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.LowLevelAPI41.MechanismParams;
using NativeULong = System.UInt32;

namespace Net.Pkcs11Interop.HighLevelAPI41.MechanismParams
{
Expand All @@ -40,7 +41,7 @@ public class CkAesCtrParams : IMechanismParams
/// </summary>
/// <param name='counterBits'>The number of bits in the counter block (cb) that shall be incremented</param>
/// <param name='cb'>Specifies the counter block (16 bytes)</param>
public CkAesCtrParams(uint counterBits, byte[] cb)
public CkAesCtrParams(NativeULong counterBits, byte[] cb)
{
_lowLevelStruct.CounterBits = 0;
_lowLevelStruct.Cb = new byte[16];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using System;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.LowLevelAPI41;
using Net.Pkcs11Interop.LowLevelAPI41.MechanismParams;

namespace Net.Pkcs11Interop.HighLevelAPI41.MechanismParams
Expand Down Expand Up @@ -63,7 +64,7 @@ public CkAriaCbcEncryptDataParams(byte[] iv, byte[] data)
{
_lowLevelStruct.Data = UnmanagedMemory.Allocate(data.Length);
UnmanagedMemory.Write(_lowLevelStruct.Data, data);
_lowLevelStruct.Length = Convert.ToUInt32(data.Length);
_lowLevelStruct.Length = NativeLongUtils.ConvertFromInt32(data.Length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using System;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.LowLevelAPI41;
using Net.Pkcs11Interop.LowLevelAPI41.MechanismParams;

namespace Net.Pkcs11Interop.HighLevelAPI41.MechanismParams
Expand Down Expand Up @@ -63,7 +64,7 @@ public CkCamelliaCbcEncryptDataParams(byte[] iv, byte[] data)
{
_lowLevelStruct.Data = UnmanagedMemory.Allocate(data.Length);
UnmanagedMemory.Write(_lowLevelStruct.Data, data);
_lowLevelStruct.Length = Convert.ToUInt32(data.Length);
_lowLevelStruct.Length = NativeLongUtils.ConvertFromInt32(data.Length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.LowLevelAPI41.MechanismParams;
using NativeULong = System.UInt32;

namespace Net.Pkcs11Interop.HighLevelAPI41.MechanismParams
{
Expand All @@ -40,7 +41,7 @@ public class CkCamelliaCtrParams : IMechanismParams
/// </summary>
/// <param name='counterBits'>The number of bits in the counter block (cb) that shall be incremented</param>
/// <param name='cb'>Specifies the counter block (16 bytes)</param>
public CkCamelliaCtrParams(uint counterBits, byte[] cb)
public CkCamelliaCtrParams(NativeULong counterBits, byte[] cb)
{
_lowLevelStruct.CounterBits = 0;
_lowLevelStruct.Cb = new byte[16];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

using System;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.LowLevelAPI41;
using Net.Pkcs11Interop.LowLevelAPI41.MechanismParams;
using NativeULong = System.UInt32;

namespace Net.Pkcs11Interop.HighLevelAPI41.MechanismParams
{
Expand All @@ -47,7 +49,7 @@ public class CkCcmParams : IMechanismParams, IDisposable
/// <param name="nonce">Nonce</param>
/// <param name="aad">Additional authentication data</param>
/// <param name="macLen">Length of the MAC (output following cipher text) in bytes</param>
public CkCcmParams(uint dataLen, byte[] nonce, byte[] aad, uint macLen)
public CkCcmParams(NativeULong dataLen, byte[] nonce, byte[] aad, NativeULong macLen)
{
_lowLevelStruct.DataLen = 0;
_lowLevelStruct.Nonce = IntPtr.Zero;
Expand All @@ -62,14 +64,14 @@ public CkCcmParams(uint dataLen, byte[] nonce, byte[] aad, uint macLen)
{
_lowLevelStruct.Nonce = UnmanagedMemory.Allocate(nonce.Length);
UnmanagedMemory.Write(_lowLevelStruct.Nonce, nonce);
_lowLevelStruct.NonceLen = Convert.ToUInt32(nonce.Length);
_lowLevelStruct.NonceLen = NativeLongUtils.ConvertFromInt32(nonce.Length);
}

if (aad != null)
{
_lowLevelStruct.AAD = UnmanagedMemory.Allocate(aad.Length);
UnmanagedMemory.Write(_lowLevelStruct.AAD, aad);
_lowLevelStruct.AADLen = Convert.ToUInt32(aad.Length);
_lowLevelStruct.AADLen = NativeLongUtils.ConvertFromInt32(aad.Length);
}

_lowLevelStruct.MACLen = macLen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

using System;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.LowLevelAPI41;
using Net.Pkcs11Interop.LowLevelAPI41.MechanismParams;
using NativeULong = System.UInt32;

namespace Net.Pkcs11Interop.HighLevelAPI41.MechanismParams
{
Expand Down Expand Up @@ -49,7 +51,7 @@ public class CkCmsSigParams : IMechanismParams, IDisposable
/// <param name='contentType'>String indicating complete MIME Content-type of message to be signed or null if the message is a MIME object</param>
/// <param name='requestedAttributes'>DER-encoded list of CMS Attributes the caller requests to be included in the signed attributes</param>
/// <param name='requiredAttributes'>DER-encoded list of CMS Attributes (with accompanying values) required to be included in the resulting signed attributes</param>
public CkCmsSigParams(ObjectHandle certificateHandle, uint? signingMechanism, uint? digestMechanism, string contentType, byte[] requestedAttributes, byte[] requiredAttributes)
public CkCmsSigParams(ObjectHandle certificateHandle, NativeULong? signingMechanism, NativeULong? digestMechanism, string contentType, byte[] requestedAttributes, byte[] requiredAttributes)
{
_lowLevelStruct.CertificateHandle = CK.CK_INVALID_HANDLE;
_lowLevelStruct.SigningMechanism = IntPtr.Zero;
Expand All @@ -67,14 +69,14 @@ public CkCmsSigParams(ObjectHandle certificateHandle, uint? signingMechanism, ui

if (signingMechanism != null)
{
byte[] bytes = ConvertUtils.UIntToBytes(signingMechanism.Value);
byte[] bytes = NativeLongUtils.ConvertToByteArray(signingMechanism.Value);
_lowLevelStruct.SigningMechanism = UnmanagedMemory.Allocate(bytes.Length);
UnmanagedMemory.Write(_lowLevelStruct.SigningMechanism, bytes);
}

if (digestMechanism != null)
{
byte[] bytes = ConvertUtils.UIntToBytes(digestMechanism.Value);
byte[] bytes = NativeLongUtils.ConvertToByteArray(digestMechanism.Value);
_lowLevelStruct.DigestMechanism = UnmanagedMemory.Allocate(bytes.Length);
UnmanagedMemory.Write(_lowLevelStruct.DigestMechanism, bytes);
}
Expand All @@ -93,14 +95,14 @@ public CkCmsSigParams(ObjectHandle certificateHandle, uint? signingMechanism, ui
{
_lowLevelStruct.RequestedAttributes = UnmanagedMemory.Allocate(requestedAttributes.Length);
UnmanagedMemory.Write(_lowLevelStruct.RequestedAttributes, requestedAttributes);
_lowLevelStruct.RequestedAttributesLen = Convert.ToUInt32(requestedAttributes.Length);
_lowLevelStruct.RequestedAttributesLen = NativeLongUtils.ConvertFromInt32(requestedAttributes.Length);
}

if (requiredAttributes != null)
{
_lowLevelStruct.RequiredAttributes = UnmanagedMemory.Allocate(requiredAttributes.Length);
UnmanagedMemory.Write(_lowLevelStruct.RequiredAttributes, requiredAttributes);
_lowLevelStruct.RequiredAttributesLen = Convert.ToUInt32(requiredAttributes.Length);
_lowLevelStruct.RequiredAttributesLen = NativeLongUtils.ConvertFromInt32(requiredAttributes.Length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using System;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.LowLevelAPI41;
using Net.Pkcs11Interop.LowLevelAPI41.MechanismParams;

namespace Net.Pkcs11Interop.HighLevelAPI41.MechanismParams
Expand Down Expand Up @@ -63,7 +64,7 @@ public CkDesCbcEncryptDataParams(byte[] iv, byte[] data)
{
_lowLevelStruct.Data = UnmanagedMemory.Allocate(data.Length);
UnmanagedMemory.Write(_lowLevelStruct.Data, data);
_lowLevelStruct.Length = Convert.ToUInt32(data.Length);
_lowLevelStruct.Length = NativeLongUtils.ConvertFromInt32(data.Length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

using System;
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.LowLevelAPI41;
using Net.Pkcs11Interop.LowLevelAPI41.MechanismParams;
using NativeULong = System.UInt32;

namespace Net.Pkcs11Interop.HighLevelAPI41.MechanismParams
{
Expand Down Expand Up @@ -50,7 +52,7 @@ public byte[] Seed
if (this._disposed)
throw new ObjectDisposedException(this.GetType().FullName);

return (_lowLevelStruct.Seed == IntPtr.Zero) ? null : UnmanagedMemory.Read(_lowLevelStruct.Seed, Convert.ToInt32(_lowLevelStruct.SeedLen));
return (_lowLevelStruct.Seed == IntPtr.Zero) ? null : UnmanagedMemory.Read(_lowLevelStruct.Seed, NativeLongUtils.ConvertToInt32(_lowLevelStruct.SeedLen));
}
}

Expand All @@ -60,7 +62,7 @@ public byte[] Seed
/// <param name="hash">Mechanism value for the base hash used in PQG generation (CKM)</param>
/// <param name="seed">Seed value used to generate PQ and G</param>
/// <param name="index">Index value for generating G</param>
public CkDsaParameterGenParam(uint hash, byte[] seed, uint index)
public CkDsaParameterGenParam(NativeULong hash, byte[] seed, NativeULong index)
{
_lowLevelStruct.Hash = 0;
_lowLevelStruct.Seed = IntPtr.Zero;
Expand All @@ -73,7 +75,7 @@ public CkDsaParameterGenParam(uint hash, byte[] seed, uint index)
{
_lowLevelStruct.Seed = UnmanagedMemory.Allocate(seed.Length);
UnmanagedMemory.Write(_lowLevelStruct.Seed, seed);
_lowLevelStruct.SeedLen = Convert.ToUInt32(seed.Length);
_lowLevelStruct.SeedLen = NativeLongUtils.ConvertFromInt32(seed.Length);
}

_lowLevelStruct.Index = index;
Expand Down
Loading