Skip to content

Commit

Permalink
[CoreWlan] Make P/Invokes have blittable signatures. (#20465)
Browse files Browse the repository at this point in the history
Contributes towards #15684.
  • Loading branch information
rolfbjarne committed Apr 22, 2024
1 parent 216ddf7 commit f2308d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 12 additions & 6 deletions src/CoreWlan/CWKeychain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static partial class CWKeychain {
[UnsupportedOSPlatform ("maccatalyst")]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainCopyWiFiEAPIdentity (/* CWKeychainDomain */ nint domain, NSDataRef ssid, out SecIdentityRef identity);
unsafe static extern OSStatus CWKeychainCopyWiFiEAPIdentity (/* CWKeychainDomain */ nint domain, NSDataRef ssid, SecIdentityRef* identity);

#if NET
[SupportedOSPlatform ("macos")]
Expand All @@ -37,7 +37,9 @@ public static bool TryFindWiFiEAPIdentity (CWKeychainDomain domain, NSData ssid,
{
identity = null;
IntPtr outPtr = IntPtr.Zero;
status = CWKeychainCopyWiFiEAPIdentity ((nint) (long) domain, ssid.GetHandle (), out outPtr);
unsafe {
status = CWKeychainCopyWiFiEAPIdentity ((nint) (long) domain, ssid.GetHandle (), &outPtr);
}
if (status == 0) {
identity = new SecIdentity (outPtr, true);
}
Expand Down Expand Up @@ -105,7 +107,7 @@ public static bool TryDeleteWiFiPassword (CWKeychainDomain domain, NSData ssid)
[UnsupportedOSPlatform ("maccatalyst")]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainFindWiFiEAPUsernameAndPassword (/* CWKeychainDomain */ nint domain, NSDataRef ssid, out NSStringRef username, out NSStringRef password);
unsafe static extern OSStatus CWKeychainFindWiFiEAPUsernameAndPassword (/* CWKeychainDomain */ nint domain, NSDataRef ssid, NSStringRef* username, NSStringRef* password);

#if NET
[SupportedOSPlatform ("macos")]
Expand All @@ -117,7 +119,9 @@ public static bool TryFindWiFiEAPUsernameAndPassword (CWKeychainDomain domain, N
password = null;
NSStringRef usernamePtr = IntPtr.Zero;
NSStringRef passwordPtr = IntPtr.Zero;
status = CWKeychainFindWiFiEAPUsernameAndPassword ((nint) (long) domain, ssid.GetHandle (), out usernamePtr, out passwordPtr);
unsafe {
status = CWKeychainFindWiFiEAPUsernameAndPassword ((nint) (long) domain, ssid.GetHandle (), &usernamePtr, &passwordPtr);
}
if (usernamePtr != IntPtr.Zero) {
username = Runtime.GetNSObject<NSString> (usernamePtr, false);
}
Expand Down Expand Up @@ -158,7 +162,7 @@ public static bool TryFindWiFiEAPUsernameAndPassword (CWKeychainDomain domain, N
[UnsupportedOSPlatform ("maccatalyst")]
#endif
[DllImport (Constants.CoreWlanLibrary)]
static extern OSStatus CWKeychainFindWiFiPassword (/* CWKeychainDomain */ nint domain, NSDataRef ssid, out NSStringRef password);
unsafe static extern OSStatus CWKeychainFindWiFiPassword (/* CWKeychainDomain */ nint domain, NSDataRef ssid, NSStringRef* password);

#if NET
[SupportedOSPlatform ("macos")]
Expand All @@ -168,7 +172,9 @@ public static bool TryFindWiFiPassword (CWKeychainDomain domain, NSData ssid, ou
{
password = null;
NSStringRef passwordPtr = IntPtr.Zero;
status = CWKeychainFindWiFiPassword ((nint) (long) domain, ssid.GetHandle (), out passwordPtr);
unsafe {
status = CWKeychainFindWiFiPassword ((nint) (long) domain, ssid.GetHandle (), &passwordPtr);
}
if (passwordPtr != IntPtr.Zero) {
password = Runtime.GetNSObject<NSString> (passwordPtr, false);
}
Expand Down
3 changes: 0 additions & 3 deletions tests/cecil-tests/BlittablePInvokes.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ public partial class BlittablePInvokes {
"System.Int32 AudioUnit.AUGraph::NewAUGraph(System.IntPtr&)",
"System.Int32 CoreVideo.CVDisplayLink::CVDisplayLinkTranslateTime(System.IntPtr,CoreVideo.CVTimeStamp,CoreVideo.CVTimeStamp&)",
"System.Int32 CoreVideo.CVMetalTextureCache::CVMetalTextureCacheCreate(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr&)",
"System.Int32 CoreWlan.CWKeychain::CWKeychainCopyWiFiEAPIdentity(System.IntPtr,System.IntPtr,System.IntPtr&)",
"System.Int32 CoreWlan.CWKeychain::CWKeychainFindWiFiEAPUsernameAndPassword(System.IntPtr,System.IntPtr,System.IntPtr&,System.IntPtr&)",
"System.Int32 CoreWlan.CWKeychain::CWKeychainFindWiFiPassword(System.IntPtr,System.IntPtr,System.IntPtr&)",
"System.Int32 Darwin.KernelQueue::kevent(System.Int32,Darwin.KernelEvent*,System.Int32,Darwin.KernelEvent*,System.Int32,Darwin.TimeSpec&)",
"System.Int32 ObjCRuntime.Runtime::_NSGetExecutablePath(System.Byte[],System.Int32&)",
"System.Int32 Security.Authorization::AuthorizationCreate(Security.AuthorizationItemSet*,Security.AuthorizationItemSet*,Security.AuthorizationFlags,System.IntPtr&)",
Expand Down

8 comments on commit f2308d1

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.