Skip to content

Commit

Permalink
fixed test case
Browse files Browse the repository at this point in the history
  • Loading branch information
tj_devel709 committed Jul 29, 2021
1 parent 5c0b615 commit 67bd7d4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
26 changes: 24 additions & 2 deletions src/AuthenticationServices/PublicPrivateKeyAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using CoreGraphics;
using Foundation;
using ObjCRuntime;
using System.Linq;

#nullable enable

Expand All @@ -24,8 +25,29 @@ public static class PublicPrivateKeyAuthentication {
[DllImport (Constants.AuthenticationServicesLibrary)]
static extern /* NSString[] */ IntPtr ASAuthorizationAllSupportedPublicKeyCredentialDescriptorTransports ();

public static /* ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport[] */ NSString[] GetAllSupportedPublicKeyCredentialDescriptorTransports () {
return NSArray.ArrayFromHandle<NSString> (ASAuthorizationAllSupportedPublicKeyCredentialDescriptorTransports ());
public static ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport[]? GetAllSupportedPublicKeyCredentialDescriptorTransports () {
NSString[]? nsStringArray = NSArray.ArrayFromHandle<NSString> (ASAuthorizationAllSupportedPublicKeyCredentialDescriptorTransports ());

if (nsStringArray == null)
return null;

ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport[]? asArray = new ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport[nsStringArray.Count ()];
for (var i = 0; i < nsStringArray.Count (); i++) {
switch (nsStringArray[i].Description){
case "usb":
asArray[i] = ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport.Usb;
break;
case "nfc":
asArray[i] = ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport.Nfc;
break;
case "ble":
asArray[i] = ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport.Bluetooth;
break;
default:
break;
}
}
return asArray;
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/authenticationservices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,11 +1009,12 @@ enum ASCOSEAlgorithmIdentifier : long {
Es256 = -7,
}

[Mac (12,0), iOS (15,0), MacCatalyst (15,0), NoWatch, NoTV]
[Native]
enum ASCOSEEllipticCurveIdentifier : long {
P256 = 1,
}
// Introduced in Xcode13 Beta3 but not used anywhere
// [Mac (12,0), iOS (15,0), MacCatalyst (15,0), NoWatch, NoTV]
// [Native]
// enum ASCOSEEllipticCurveIdentifier : long {
// P256 = 1,
// }

interface IASAuthorizationPublicKeyCredentialAssertion { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ public void Setup ()
[Test]
public void GetAllSupportedPublicKeyCredentialDescriptorTransports ()
{
var transports = PublicPrivateKeyAuthentication.GetAllSupportedPublicKeyCredentialDescriptorTransports ();
Assert.IsNotNull (PublicPrivateKeyAuthentication.GetAllSupportedPublicKeyCredentialDescriptorTransports (), "The transports should not be null");

// since there is no default enum value, make sure there is not
// more than one ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport.Usb
var usbCounter = 0;
foreach (var transport in transports) {
if (transport == ASAuthorizationSecurityKeyPublicKeyCredentialDescriptorTransport.Usb)
usbCounter++;
}
Assert.LessOrEqual (usbCounter, 1, "There were multiple usb transports found. Add any new transports to src/AuthenticationServices/PublicPrivateKeyAuthentication.cs");
}
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/xtro-sharpie/common-AuthenticationServices.ignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# xtro did not pick up on this enum
!unknown-native-enum! ASCOSEAlgorithmIdentifier bound
!unknown-native-enum! ASCOSEEllipticCurveIdentifier bound

0 comments on commit 67bd7d4

Please sign in to comment.