Skip to content

Commit 43e2cd3

Browse files
joegoldman2abergs
andauthored
List<PublicKeyCredentialDescriptor>/IEnumerable<PublicKeyCredentialDescriptor> to IReadOnlyList<PublicKeyCredentialDescriptor> (#447)
* Change excludeCredentials from List<PublicKeyCredentialDescriptor> to IEnumerable<PublicKeyCredentialDescriptor> * Use Any() instead of Count() * Remove unnecessary ToList() * Fix README.md * IEnumerable -> IReadOnlyList * Revert README.md * Apply suggestions from review. --------- Co-authored-by: Anders Åberg <anders@andersaberg.com>
1 parent 5e5f289 commit 43e2cd3

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

Src/Fido2.Models/AssertionOptions.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class AssertionOptions : Fido2ResponseBase
3636
/// This OPTIONAL member contains a list of PublicKeyCredentialDescriptor objects representing public key credentials acceptable to the caller, in descending order of the caller’s preference(the first item in the list is the most preferred credential, and so on down the list)
3737
/// </summary>
3838
[JsonPropertyName("allowCredentials")]
39-
public IEnumerable<PublicKeyCredentialDescriptor> AllowCredentials { get; set; }
39+
public IReadOnlyList<PublicKeyCredentialDescriptor> AllowCredentials { get; set; } = Array.Empty<PublicKeyCredentialDescriptor>();
4040

4141
/// <summary>
4242
/// This member describes the Relying Party's requirements regarding user verification for the get() operation. Eligible authenticators are filtered to only those capable of satisfying this requirement
@@ -51,7 +51,12 @@ public class AssertionOptions : Fido2ResponseBase
5151
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
5252
public AuthenticationExtensionsClientInputs Extensions { get; set; }
5353

54-
public static AssertionOptions Create(Fido2Configuration config, byte[] challenge, IEnumerable<PublicKeyCredentialDescriptor> allowedCredentials, UserVerificationRequirement? userVerification, AuthenticationExtensionsClientInputs extensions)
54+
public static AssertionOptions Create(
55+
Fido2Configuration config,
56+
byte[] challenge,
57+
IReadOnlyList<PublicKeyCredentialDescriptor> allowedCredentials,
58+
UserVerificationRequirement? userVerification,
59+
AuthenticationExtensionsClientInputs extensions)
5560
{
5661
return new AssertionOptions()
5762
{
@@ -60,7 +65,7 @@ public static AssertionOptions Create(Fido2Configuration config, byte[] challeng
6065
Challenge = challenge,
6166
Timeout = config.Timeout,
6267
RpId = config.ServerDomain,
63-
AllowCredentials = allowedCredentials ?? Array.Empty<PublicKeyCredentialDescriptor>(),
68+
AllowCredentials = allowedCredentials,
6469
UserVerification = userVerification,
6570
Extensions = extensions
6671
};

Src/Fido2.Models/CredentialCreateOptions.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public sealed class CredentialCreateOptions : Fido2ResponseBase
6161
/// This member is intended for use by Relying Parties that wish to limit the creation of multiple credentials for the same account on a single authenticator.The client is requested to return an error if the new credential would be created on an authenticator that also contains one of the credentials enumerated in this parameter.
6262
/// </summary>
6363
[JsonPropertyName("excludeCredentials")]
64-
public List<PublicKeyCredentialDescriptor> ExcludeCredentials { get; set; }
64+
public IReadOnlyList<PublicKeyCredentialDescriptor> ExcludeCredentials { get; set; } = Array.Empty<PublicKeyCredentialDescriptor>();
6565

6666
/// <summary>
6767
/// This OPTIONAL member contains additional parameters requesting additional processing by the client and authenticator. For example, if transaction confirmation is sought from the user, then the prompt string might be included as an extension.
@@ -70,7 +70,14 @@ public sealed class CredentialCreateOptions : Fido2ResponseBase
7070
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
7171
public AuthenticationExtensionsClientInputs Extensions { get; set; }
7272

73-
public static CredentialCreateOptions Create(Fido2Configuration config, byte[] challenge, Fido2User user, AuthenticatorSelection authenticatorSelection, AttestationConveyancePreference attestationConveyancePreference, List<PublicKeyCredentialDescriptor> excludeCredentials, AuthenticationExtensionsClientInputs extensions)
73+
public static CredentialCreateOptions Create(
74+
Fido2Configuration config,
75+
byte[] challenge,
76+
Fido2User user,
77+
AuthenticatorSelection authenticatorSelection,
78+
AttestationConveyancePreference attestationConveyancePreference,
79+
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
80+
AuthenticationExtensionsClientInputs extensions)
7481
{
7582
return new CredentialCreateOptions
7683
{
@@ -96,7 +103,7 @@ public static CredentialCreateOptions Create(Fido2Configuration config, byte[] c
96103
},
97104
AuthenticatorSelection = authenticatorSelection,
98105
Attestation = attestationConveyancePreference,
99-
ExcludeCredentials = excludeCredentials ?? new List<PublicKeyCredentialDescriptor>(),
106+
ExcludeCredentials = excludeCredentials,
100107
Extensions = extensions
101108
};
102109
}

Src/Fido2/Fido2.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Fido2(
3030
/// <param name="excludeCredentials">Recommended. This member is intended for use by Relying Parties that wish to limit the creation of multiple credentials for the same account on a single authenticator. The client is requested to return an error if the new credential would be created on an authenticator that also contains one of the credentials enumerated in this parameter.</param>
3131
public CredentialCreateOptions RequestNewCredential(
3232
Fido2User user,
33-
List<PublicKeyCredentialDescriptor> excludeCredentials,
33+
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
3434
AuthenticationExtensionsClientInputs? extensions = null)
3535
{
3636
return RequestNewCredential(user, excludeCredentials, AuthenticatorSelection.Default, AttestationConveyancePreference.None, extensions);
@@ -44,7 +44,7 @@ public CredentialCreateOptions RequestNewCredential(
4444
/// <param name="excludeCredentials">Recommended. This member is intended for use by Relying Parties that wish to limit the creation of multiple credentials for the same account on a single authenticator. The client is requested to return an error if the new credential would be created on an authenticator that also contains one of the credentials enumerated in this parameter.</param>
4545
public CredentialCreateOptions RequestNewCredential(
4646
Fido2User user,
47-
List<PublicKeyCredentialDescriptor> excludeCredentials,
47+
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
4848
AuthenticatorSelection authenticatorSelection,
4949
AttestationConveyancePreference attestationPreference,
5050
AuthenticationExtensionsClientInputs? extensions = null)
@@ -84,7 +84,7 @@ public async Task<MakeNewCredentialResult> MakeNewCredentialAsync(
8484
/// </summary>
8585
/// <returns></returns>
8686
public AssertionOptions GetAssertionOptions(
87-
IEnumerable<PublicKeyCredentialDescriptor> allowedCredentials,
87+
IReadOnlyList<PublicKeyCredentialDescriptor> allowedCredentials,
8888
UserVerificationRequirement? userVerification,
8989
AuthenticationExtensionsClientInputs? extensions = null)
9090
{

Src/Fido2/IFido2.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Fido2NetLib;
99
public interface IFido2
1010
{
1111
AssertionOptions GetAssertionOptions(
12-
IEnumerable<PublicKeyCredentialDescriptor> allowedCredentials,
12+
IReadOnlyList<PublicKeyCredentialDescriptor> allowedCredentials,
1313
UserVerificationRequirement? userVerification,
1414
AuthenticationExtensionsClientInputs? extensions = null);
1515

@@ -30,12 +30,12 @@ Task<MakeNewCredentialResult> MakeNewCredentialAsync(
3030

3131
CredentialCreateOptions RequestNewCredential(
3232
Fido2User user,
33-
List<PublicKeyCredentialDescriptor> excludeCredentials,
33+
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
3434
AuthenticationExtensionsClientInputs? extensions = null);
3535

3636
CredentialCreateOptions RequestNewCredential(
3737
Fido2User user,
38-
List<PublicKeyCredentialDescriptor> excludeCredentials,
38+
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
3939
AuthenticatorSelection authenticatorSelection,
4040
AttestationConveyancePreference attestationPreference,
4141
AuthenticationExtensionsClientInputs? extensions = null);

0 commit comments

Comments
 (0)