From 6315c0ac564e03310dd364af64736714aa97f088 Mon Sep 17 00:00:00 2001 From: Kyungwook Tak Date: Wed, 2 Nov 2016 14:44:06 +0900 Subject: [PATCH] Fix bug: size_t should be marshalled to UIntPtr size_t size differ in 32bit and 64bit arch so UintPtr should be used Change-Id: I3681c20950ac58f815183749a746180ff7a7b835 Signed-off-by: Kyungwook Tak --- .../Interop/Interop.CkmcTypes.cs | 17 +++++++++-------- .../Tizen.Security.SecureRepository/Certificate.cs | 2 +- .../Tizen.Security.SecureRepository/Key.cs | 6 +++--- .../Tizen.Security.SecureRepository/Pkcs12.cs | 2 +- .../SafeRawBufferHandle.cs | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Tizen.Security.SecureRepository/Interop/Interop.CkmcTypes.cs b/src/Tizen.Security.SecureRepository/Interop/Interop.CkmcTypes.cs index 69fbfb0..98b87ac 100644 --- a/src/Tizen.Security.SecureRepository/Interop/Interop.CkmcTypes.cs +++ b/src/Tizen.Security.SecureRepository/Interop/Interop.CkmcTypes.cs @@ -36,17 +36,18 @@ internal static partial class Interop [StructLayout(LayoutKind.Sequential)] internal struct CkmcKey { - public CkmcKey(IntPtr binary, int keySize, int keyType, IntPtr password) + public CkmcKey(IntPtr binary, int keySize, int keyType, string password) { this.rawKey = binary; - this.size = (uint)keySize; + this.size = (UIntPtr)keySize; this.keyType = keyType; this.password = password; } public readonly IntPtr rawKey; - public readonly uint size; + public readonly UIntPtr size; public readonly int keyType; - public readonly IntPtr password; + [MarshalAs(UnmanagedType.LPStr)] + public readonly string password; } [StructLayout(LayoutKind.Sequential)] @@ -55,11 +56,11 @@ internal static partial class Interop public CkmcCert(IntPtr binary, int size, int dataFormat) { this.rawCert = binary; - this.size = (uint)size; + this.size = (UIntPtr)size; this.dataFormat = dataFormat; } public readonly IntPtr rawCert; - public readonly uint size; + public readonly UIntPtr size; public readonly int dataFormat; } @@ -69,10 +70,10 @@ internal static partial class Interop public CkmcRawBuffer(IntPtr binary, int size) { this.data = binary; - this.size = (uint)size; + this.size = (UIntPtr)size; } public readonly IntPtr data; - public readonly uint size; + public readonly UIntPtr size; } [StructLayout(LayoutKind.Sequential)] diff --git a/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/Certificate.cs b/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/Certificate.cs index 0dfaae2..85adb54 100755 --- a/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/Certificate.cs +++ b/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/Certificate.cs @@ -58,7 +58,7 @@ namespace Tizen.Security.SecureRepository base.SetHandle(ptrCkmcCert); CkmcCert ckmcCert = Marshal.PtrToStructure(ptrCkmcCert); - Binary = new byte[ckmcCert.size]; + Binary = new byte[(int)ckmcCert.size]; Marshal.Copy(ckmcCert.rawCert, Binary, 0, Binary.Length); Format = (DataFormat)ckmcCert.dataFormat; } diff --git a/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/Key.cs b/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/Key.cs index 615f2a9..3035f8e 100755 --- a/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/Key.cs +++ b/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/Key.cs @@ -44,10 +44,10 @@ namespace Tizen.Security.SecureRepository base.SetHandle(ptr); CkmcKey ckmcKey = Marshal.PtrToStructure(handle); - Binary = new byte[ckmcKey.size]; + Binary = new byte[(int)ckmcKey.size]; Marshal.Copy(ckmcKey.rawKey, Binary, 0, Binary.Length); Type = (KeyType)ckmcKey.keyType; - BinaryPassword = Marshal.PtrToStringAnsi(ckmcKey.password); + BinaryPassword = ckmcKey.password; } /// @@ -80,7 +80,7 @@ namespace Tizen.Security.SecureRepository return new Interop.CkmcKey(new PinnedObject(bin), bin.Length, (int)Type, - new PinnedObject(BinaryPassword)); + BinaryPassword); } /// diff --git a/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/Pkcs12.cs b/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/Pkcs12.cs index cc5c52c..a03b442 100755 --- a/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/Pkcs12.cs +++ b/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/Pkcs12.cs @@ -117,7 +117,7 @@ namespace Tizen.Security.SecureRepository internal CkmcPkcs12 ToCkmcPkcs12() { Interop.CkmcKey ckmcKey = (PrivateKey != null) ? - PrivateKey.ToCkmcKey() : new Interop.CkmcKey(IntPtr.Zero, 0, 0, IntPtr.Zero); + PrivateKey.ToCkmcKey() : new Interop.CkmcKey(IntPtr.Zero, 0, 0, null); Interop.CkmcCert ckmcCert = (Certificate != null) ? Certificate.ToCkmcCert() : new Interop.CkmcCert(IntPtr.Zero, 0, 0); SafeCertificateListHandle ckmcCaCerts = new SafeCertificateListHandle(CaChain); diff --git a/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/SafeRawBufferHandle.cs b/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/SafeRawBufferHandle.cs index 54d383b..3283d62 100755 --- a/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/SafeRawBufferHandle.cs +++ b/src/Tizen.Security.SecureRepository/Tizen.Security.SecureRepository/SafeRawBufferHandle.cs @@ -30,7 +30,7 @@ namespace Tizen.Security.SecureRepository return; CkmcRawBuffer buff = Marshal.PtrToStructure(ptrRawBuffer); - byte[] data = new byte[buff.size]; + byte[] data = new byte[(int)buff.size]; Marshal.Copy(buff.data, data, 0, data.Length); this.Data = data; -- 2.7.4