Skip to content

[LocalAuthentication] Implement Xcode 16.0 beta 1-6 changes. #20891

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

Merged
merged 7 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/LocalAuthentication/LADomainStateCompanion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#if !WATCH && !TV
using Foundation;

namespace LocalAuthentication {
public partial class LADomainStateCompanion {
/// <summary>Returns all the companions paired with this device, as a bitmask of <see cref="LACompanionType" />.</summary>
public LACompanionType AvailableCompanionTypes {
get {
var setOfCompanions = WeakAvailableCompanionTypes;
var rv = default (LACompanionType);
foreach (var value in setOfCompanions) {
var companion = (LACompanionType) (long) value.LongValue;
rv |= companion;
}
return rv;
}
}
}
}
#endif // !WATCH && !TV
9 changes: 9 additions & 0 deletions src/LocalAuthentication/LAEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ public enum LAPolicy : long {
[MacCatalyst (13, 1)]
DeviceOwnerAuthenticationWithBiometrics = 1,
DeviceOwnerAuthentication = 2,
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use 'DeviceOwnerAuthenticationWithCompanion' instead.")]
[NoiOS]
[NoWatch]
[NoMacCatalyst]
DeviceOwnerAuthenticationWithWatch = 3,
[NoWatch, NoTV, MacCatalyst (18, 0), Mac (15, 0), iOS (18, 0)]
DeviceOwnerAuthenticationWithCompanion = 3,
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use 'DeviceOwnerAuthenticationWithBiometricsOrCompanion' instead.")]
[NoiOS]
[NoWatch]
[NoMacCatalyst]
DeviceOwnerAuthenticationWithBiometricsOrWatch = 4,
[NoWatch, NoTV, MacCatalyst (18, 0), Mac (15, 0), iOS (18, 0)]
DeviceOwnerAuthenticationWithBiometricsOrCompanion = 4,
[Obsolete ("Use DeviceOwnerAuthenticationWithBiometricsOrWatch enum value instead.")]
[NoiOS]
[NoWatch]
Expand Down Expand Up @@ -65,6 +71,7 @@ public enum LAStatus : long {
#endif
AppCancel = -9,
InvalidContext = -10,
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use 'CompanionNotAvailable' instead.")]
[NoiOS, NoWatch, NoMacCatalyst]
WatchNotAvailable = -11,
[NoiOS, NoWatch, NoMacCatalyst]
Expand All @@ -83,6 +90,8 @@ public enum LAStatus : long {
[MacCatalyst (13, 1)]
BiometryLockout = -8,
NotInteractive = -1004,
[NoWatch]
CompanionNotAvailable = -11,
}

/// <summary>Enumerates local authentication credential types.</summary>
Expand Down
3 changes: 3 additions & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,9 @@ JAVASCRIPTCORE_SOURCES = \
LOCALAUTHENTICATION_API_SOURCES = \
LocalAuthentication/LAEnums.cs \

LOCALAUTHENTICATION_SOURCES = \
LocalAuthentication/LADomainStateCompanion.cs \

# MapKit

MAPKIT_API_SOURCES = \
Expand Down
160 changes: 158 additions & 2 deletions src/localauthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace LocalAuthentication {

/// <summary>Enumerates supported biometric authentication types.</summary>
[NoWatch]
[Watch (11, 0)]
[NoTV]
[MacCatalyst (13, 1)]
[Native]
Expand Down Expand Up @@ -77,7 +77,9 @@ interface LAContext {
[Export ("evaluateAccessControl:operation:localizedReason:reply:")]
void EvaluateAccessControl (SecAccessControl accessControl, LAAccessControlOperation operation, string localizedReason, Action<bool, NSError> reply);


[Deprecated (PlatformName.iOS, 18, 0, message: "Use 'LADomainStateBiometry.StateHash' instead.")]
[Deprecated (PlatformName.MacOSX, 15, 0, message: "Use 'LADomainStateBiometry.StateHash' instead.")]
[Deprecated (PlatformName.MacCatalyst, 18, 0, message: "Use 'LADomainStateBiometry.StateHash' instead.")]
[MacCatalyst (13, 1)]
[Export ("evaluatedPolicyDomainState")]
[NullAllowed]
Expand Down Expand Up @@ -119,6 +121,10 @@ interface LAContext {
[MacCatalyst (13, 1)]
[Export ("biometryType")]
LABiometryType BiometryType { get; }

[Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), NoWatch]
[Export ("domainState")]
LADomainState DomainState { get; }
}

[Mac (13, 0), iOS (16, 0), MacCatalyst (16, 0), NoWatch, NoTV]
Expand Down Expand Up @@ -294,4 +300,154 @@ interface LASecret {
[Export ("loadDataWithCompletion:")]
void LoadData (LASecretCompletionHandler handler);
}

[Flags]
[Native]
[Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), Watch (11, 0), NoTV]
enum LACompanionType : long {
None = 0,
[NoiOS, NoWatch, NoTV, NoMacCatalyst]
Watch = 1 << 0,
[NoMac, NoWatch, NoTV]
Mac = 1 << 1,
}

[Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), NoWatch]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface LADomainStateBiometry {
[Export ("biometryType")]
LABiometryType BiometryType { get; }

[Export ("stateHash"), NullAllowed]
NSData StateHash { get; }
}

[Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), NoWatch]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface LADomainStateCompanion {
[Export ("availableCompanionTypes")]
NSSet<NSNumber> WeakAvailableCompanionTypes { get; }

[Export ("stateHash"), NullAllowed]
NSData StateHash { get; }

[Export ("stateHashForCompanionType:")]
[return: NullAllowed]
NSData GetStateHash (LACompanionType companionType);
}

[Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), NoWatch]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface LADomainState {
[Export ("biometry")]
LADomainStateBiometry Biometry { get; }

[Export ("companion")]
LADomainStateCompanion Companion { get; }

[Export ("stateHash"), NullAllowed]
NSData StateHash { get; }
}

[Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), Watch (11, 0)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface LAEnvironment {
[Export ("addObserver:")]
void AddObserver (ILAEnvironmentObserver observer);

[Export ("removeObserver:")]
void RemoveObserver (ILAEnvironmentObserver observer);

[Static]
[Export ("currentUser")]
LAEnvironment CurrentUser { get; }

[Export ("state")]
LAEnvironmentState State { get; }
}

[Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), Watch (11, 0)]
[Protocol (BackwardsCompatibleCodeGeneration = false), Model]
[BaseType (typeof (NSObject))]
interface LAEnvironmentObserver {
[Export ("environment:stateDidChangeFromOldState:")]
void StateDidChangeFromOldState (LAEnvironment environment, LAEnvironmentState oldState);
}

interface ILAEnvironmentObserver { }

[Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), Watch (11, 0)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface LAEnvironmentMechanism {
[Export ("isUsable")]
bool IsUsable { get; }

[Export ("localizedName")]
string LocalizedName { get; }

[Export ("iconSystemName")]
string IconSystemName { get; }
}

[Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), Watch (11, 0)]
[BaseType (typeof (LAEnvironmentMechanism))]
[DisableDefaultCtor]
interface LAEnvironmentMechanismBiometry {
[Export ("biometryType")]
LABiometryType BiometryType { get; }

[Export ("isEnrolled")]
bool IsEnrolled { get; }

[Export ("isLockedOut")]
bool IsLockedOut { get; }

[Export ("stateHash")]
NSData StateHash { get; }

[Export ("builtInSensorInaccessible")]
bool BuiltInSensorInaccessible { get; }
}

[Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), Watch (11, 0)]
[BaseType (typeof (LAEnvironmentMechanism))]
[DisableDefaultCtor]
interface LAEnvironmentMechanismCompanion {
[Export ("type")]
LACompanionType Type { get; }

[Export ("stateHash"), NullAllowed]
NSData StateHash { get; }
}

[Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), Watch (11, 0)]
[BaseType (typeof (LAEnvironmentMechanism))]
[DisableDefaultCtor]
interface LAEnvironmentMechanismUserPassword {
[Export ("isSet")]
bool IsSet { get; }
}

[Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0), Watch (11, 0)]
[BaseType (typeof (NSObject))]
[DisableDefaultCtor]
interface LAEnvironmentState : NSCopying {
[Export ("biometry"), NullAllowed]
LAEnvironmentMechanismBiometry Biometry { get; }

[Export ("userPassword"), NullAllowed]
LAEnvironmentMechanismUserPassword UserPassword { get; }

[NoWatch]
[Export ("companions")]
LAEnvironmentMechanismCompanion [] Companions { get; }

[Export ("allMechanisms")]
LAEnvironmentMechanism [] AllMechanisms { get; }
}
}
49 changes: 49 additions & 0 deletions tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13201,11 +13201,16 @@ F:LocalAuthentication.LABiometryType.FaceId
F:LocalAuthentication.LABiometryType.None
F:LocalAuthentication.LABiometryType.OpticId
F:LocalAuthentication.LABiometryType.TouchId
F:LocalAuthentication.LACompanionType.Mac
F:LocalAuthentication.LACompanionType.None
F:LocalAuthentication.LACompanionType.Watch
F:LocalAuthentication.LACredentialType.ApplicationPassword
F:LocalAuthentication.LACredentialType.SmartCardPin
F:LocalAuthentication.LAPolicy.DeviceOwnerAuthentication
F:LocalAuthentication.LAPolicy.DeviceOwnerAuthenticationWithBiometrics
F:LocalAuthentication.LAPolicy.DeviceOwnerAuthenticationWithBiometricsOrCompanion
F:LocalAuthentication.LAPolicy.DeviceOwnerAuthenticationWithBiometricsOrWatch
F:LocalAuthentication.LAPolicy.DeviceOwnerAuthenticationWithCompanion
F:LocalAuthentication.LAPolicy.DeviceOwnerAuthenticationWithWatch
F:LocalAuthentication.LAPolicy.DeviceOwnerAuthenticationWithWristDetection
F:LocalAuthentication.LARightState.Authorized
Expand All @@ -13218,6 +13223,7 @@ F:LocalAuthentication.LAStatus.BiometryLockout
F:LocalAuthentication.LAStatus.BiometryNotAvailable
F:LocalAuthentication.LAStatus.BiometryNotEnrolled
F:LocalAuthentication.LAStatus.BiometryNotPaired
F:LocalAuthentication.LAStatus.CompanionNotAvailable
F:LocalAuthentication.LAStatus.InvalidContext
F:LocalAuthentication.LAStatus.InvalidDimension
F:LocalAuthentication.LAStatus.NotInteractive
Expand Down Expand Up @@ -38743,6 +38749,7 @@ M:LinkPresentation.LPMetadataProvider.StartFetchingMetadata(Foundation.NSUrl,Sys
M:LinkPresentation.LPMetadataProvider.StartFetchingMetadata(Foundation.NSUrlRequest,System.Action{LinkPresentation.LPLinkMetadata,Foundation.NSError})
M:LinkPresentation.LPMetadataProvider.StartFetchingMetadataAsync(Foundation.NSUrl)
M:LinkPresentation.LPMetadataProvider.StartFetchingMetadataAsync(Foundation.NSUrlRequest)
M:LocalAuthentication.ILAEnvironmentObserver.StateDidChangeFromOldState(LocalAuthentication.LAEnvironment,LocalAuthentication.LAEnvironmentState)
M:LocalAuthentication.LAAuthenticationRequirement.GetBiometryRequirement(LocalAuthentication.LABiometryFallbackRequirement)
M:LocalAuthentication.LAContext.CanEvaluatePolicy(LocalAuthentication.LAPolicy,Foundation.NSError@)
M:LocalAuthentication.LAContext.EvaluateAccessControl(Security.SecAccessControl,LocalAuthentication.LAAccessControlOperation,System.String,System.Action{System.Boolean,Foundation.NSError})
Expand All @@ -38751,6 +38758,11 @@ M:LocalAuthentication.LAContext.EvaluatePolicyAsync(LocalAuthentication.LAPolicy
M:LocalAuthentication.LAContext.Invalidate
M:LocalAuthentication.LAContext.IsCredentialSet(LocalAuthentication.LACredentialType)
M:LocalAuthentication.LAContext.SetCredentialType(Foundation.NSData,LocalAuthentication.LACredentialType)
M:LocalAuthentication.LADomainStateCompanion.GetStateHash(LocalAuthentication.LACompanionType)
M:LocalAuthentication.LAEnvironment.AddObserver(LocalAuthentication.ILAEnvironmentObserver)
M:LocalAuthentication.LAEnvironment.RemoveObserver(LocalAuthentication.ILAEnvironmentObserver)
M:LocalAuthentication.LAEnvironmentObserver.StateDidChangeFromOldState(LocalAuthentication.LAEnvironment,LocalAuthentication.LAEnvironmentState)
M:LocalAuthentication.LAEnvironmentState.Copy(Foundation.NSZone)
M:LocalAuthentication.LAPrivateKey.CanDecrypt(Security.SecKeyAlgorithm)
M:LocalAuthentication.LAPrivateKey.CanExchangeKeys(Security.SecKeyAlgorithm)
M:LocalAuthentication.LAPrivateKey.CanSign(Security.SecKeyAlgorithm)
Expand Down Expand Up @@ -68190,6 +68202,7 @@ P:LocalAuthentication.LAAuthenticationRequirement.DefaultRequirement
P:LocalAuthentication.LABiometryFallbackRequirement.DefaultRequirement
P:LocalAuthentication.LABiometryFallbackRequirement.DevicePasscodeRequirement
P:LocalAuthentication.LAContext.BiometryType
P:LocalAuthentication.LAContext.DomainState
P:LocalAuthentication.LAContext.EvaluatedPolicyDomainState
P:LocalAuthentication.LAContext.InteractionNotAllowed
P:LocalAuthentication.LAContext.LocalizedCancelTitle
Expand All @@ -68198,6 +68211,30 @@ P:LocalAuthentication.LAContext.LocalizedReason
P:LocalAuthentication.LAContext.MaxBiometryFailures
P:LocalAuthentication.LAContext.TouchIdAuthenticationAllowableReuseDuration
P:LocalAuthentication.LAContext.TouchIdAuthenticationMaximumAllowableReuseDuration
P:LocalAuthentication.LADomainState.Biometry
P:LocalAuthentication.LADomainState.Companion
P:LocalAuthentication.LADomainState.StateHash
P:LocalAuthentication.LADomainStateBiometry.BiometryType
P:LocalAuthentication.LADomainStateBiometry.StateHash
P:LocalAuthentication.LADomainStateCompanion.StateHash
P:LocalAuthentication.LADomainStateCompanion.WeakAvailableCompanionTypes
P:LocalAuthentication.LAEnvironment.CurrentUser
P:LocalAuthentication.LAEnvironment.State
P:LocalAuthentication.LAEnvironmentMechanism.IconSystemName
P:LocalAuthentication.LAEnvironmentMechanism.IsUsable
P:LocalAuthentication.LAEnvironmentMechanism.LocalizedName
P:LocalAuthentication.LAEnvironmentMechanismBiometry.BiometryType
P:LocalAuthentication.LAEnvironmentMechanismBiometry.BuiltInSensorInaccessible
P:LocalAuthentication.LAEnvironmentMechanismBiometry.IsEnrolled
P:LocalAuthentication.LAEnvironmentMechanismBiometry.IsLockedOut
P:LocalAuthentication.LAEnvironmentMechanismBiometry.StateHash
P:LocalAuthentication.LAEnvironmentMechanismCompanion.StateHash
P:LocalAuthentication.LAEnvironmentMechanismCompanion.Type
P:LocalAuthentication.LAEnvironmentMechanismUserPassword.IsSet
P:LocalAuthentication.LAEnvironmentState.AllMechanisms
P:LocalAuthentication.LAEnvironmentState.Biometry
P:LocalAuthentication.LAEnvironmentState.Companions
P:LocalAuthentication.LAEnvironmentState.UserPassword
P:LocalAuthentication.LAPersistedRight.Key
P:LocalAuthentication.LAPersistedRight.Secret
P:LocalAuthentication.LAPrivateKey.PublicKey
Expand Down Expand Up @@ -80685,8 +80722,20 @@ T:LinkPresentation.LPErrorCode
T:LinkPresentation.LPLinkMetadata
T:LinkPresentation.LPLinkView
T:LinkPresentation.LPMetadataProvider
T:LocalAuthentication.ILAEnvironmentObserver
T:LocalAuthentication.LAAuthenticationRequirement
T:LocalAuthentication.LABiometryFallbackRequirement
T:LocalAuthentication.LACompanionType
T:LocalAuthentication.LADomainState
T:LocalAuthentication.LADomainStateBiometry
T:LocalAuthentication.LADomainStateCompanion
T:LocalAuthentication.LAEnvironment
T:LocalAuthentication.LAEnvironmentMechanism
T:LocalAuthentication.LAEnvironmentMechanismBiometry
T:LocalAuthentication.LAEnvironmentMechanismCompanion
T:LocalAuthentication.LAEnvironmentMechanismUserPassword
T:LocalAuthentication.LAEnvironmentObserver
T:LocalAuthentication.LAEnvironmentState
T:LocalAuthentication.LAPersistedRight
T:LocalAuthentication.LAPrivateKey
T:LocalAuthentication.LAPrivateKeyCompletionHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#if HAS_LOCALAUTHENTICATION
using System;
using System.Collections;
using System.Collections.Generic;

using NUnit.Framework;

using Foundation;
using LocalAuthentication;

namespace MonoTouchFixtures.LocalAuthentication {

[TestFixture]
[Preserve (AllMembers = true)]
public class LADomainStateCompanionTest {

[Test]
public void AvailableCompanionTypes ()
{
TestRuntime.AssertXcodeVersion (16, 0);

using var context = new LAContext ();
Assert.IsNotNull (context.DomainState, "DomainState");
Assert.IsNotNull (context.DomainState.Companion, "DomainState.Companion");
Assert.IsNotNull (context.DomainState.Companion.WeakAvailableCompanionTypes, "DomainState.Companion.WeakAvailableCompanionTypes");
Assert.AreEqual (LACompanionType.None, context.DomainState.Companion.AvailableCompanionTypes, "DomainState.Companion.AvailableCompanionTypes");
}
}
}
#endif // HAS_LOCALAUTHENTICATION
Loading