Skip to content

Commit 2a19063

Browse files
authored
Use Collection Expressions in the library (#613)
* Use Collection Expressions Mostly cleaning up default values * In more places
1 parent e230606 commit 2a19063

File tree

11 files changed

+16
-17
lines changed

11 files changed

+16
-17
lines changed

Src/Fido2.Development/DevelopmentInMemoryStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public Task<List<Fido2User>> GetUsersByCredentialIdAsync(byte[] credentialId, Ca
5151
var cred = _storedCredentials.FirstOrDefault(c => c.Descriptor.Id.AsSpan().SequenceEqual(credentialId));
5252

5353
if (cred is null)
54-
return Task.FromResult(new List<Fido2User>());
54+
return Task.FromResult<List<Fido2User>>([]);
5555

5656
return Task.FromResult(_storedUsers.Where(u => u.Value.Id.SequenceEqual(cred.UserId)).Select(u => u.Value).ToList());
5757
}

Src/Fido2.Models/AssertionOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class AssertionOptions
4141
/// 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)
4242
/// </summary>
4343
[JsonPropertyName("allowCredentials")]
44-
public IReadOnlyList<PublicKeyCredentialDescriptor> AllowCredentials { get; set; } = Array.Empty<PublicKeyCredentialDescriptor>();
44+
public IReadOnlyList<PublicKeyCredentialDescriptor> AllowCredentials { get; set; } = [];
4545

4646
/// <summary>
4747
/// This member describes the Relying Party's requirements regarding user verification for the get() operation.
@@ -54,7 +54,7 @@ public class AssertionOptions
5454
/// This OPTIONAL member contains zero or more elements from <see cref="PublicKeyCredentialHint"/> to guide the user agent in interacting with the user. Note that the elements have type DOMString despite being taken from that enumeration.
5555
/// </summary>
5656
[JsonPropertyName("hints")]
57-
public IReadOnlyList<PublicKeyCredentialHint> Hints { get; set; } = Array.Empty<PublicKeyCredentialHint>();
57+
public IReadOnlyList<PublicKeyCredentialHint> Hints { get; set; } = [];
5858

5959
/// <summary>
6060
/// This OPTIONAL member contains additional parameters requesting additional processing by the client and authenticator.

Src/Fido2.Models/Converters/EnumNameMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static IEnumerable<string> GetNames()
4141

4242
private static FrozenDictionary<TEnum, string> GetIdToNameMap()
4343
{
44-
var items = new List<KeyValuePair<TEnum, string>>();
44+
List<KeyValuePair<TEnum, string>> items = [];
4545

4646
foreach (var field in typeof(TEnum).GetFields(BindingFlags.Public | BindingFlags.Static))
4747
{

Src/Fido2.Models/CredentialCreateOptions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public sealed class CredentialCreateOptions
6767

6868
#nullable enable
6969

70-
private IReadOnlyList<PublicKeyCredentialHint> _hints = Array.Empty<PublicKeyCredentialHint>();
70+
private IReadOnlyList<PublicKeyCredentialHint> _hints = [];
7171

7272
/// <summary>
7373
/// Guides the user agent in interacting with the user. This OPTIONAL member contains zero or more elements from <see cref="PublicKeyCredentialHint" />.
@@ -126,8 +126,8 @@ public static CredentialCreateOptions Create(
126126
AttestationConveyancePreference attestationConveyancePreference,
127127
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
128128
AuthenticationExtensionsClientInputs? extensions,
129-
IReadOnlyList<PubKeyCredParam> pubKeyCredParams)
130-
129+
IReadOnlyList<PubKeyCredParam> pubKeyCredParams)
130+
131131
{
132132
return new CredentialCreateOptions
133133
{
@@ -184,8 +184,8 @@ public sealed class PubKeyCredParam(
184184
public static readonly PubKeyCredParam PS384 = new(COSE.Algorithm.PS384);
185185
public static readonly PubKeyCredParam PS512 = new(COSE.Algorithm.PS512);
186186
public static readonly PubKeyCredParam Ed25519 = new(COSE.Algorithm.EdDSA);
187-
public static readonly PubKeyCredParam RS1 = new(COSE.Algorithm.RS1);
188-
187+
public static readonly PubKeyCredParam RS1 = new(COSE.Algorithm.RS1);
188+
189189
/// <summary>
190190
/// The default algorithms supported by the library
191191
/// </summary>

Src/Fido2/Asn1Element.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public static Asn1Element Decode(ReadOnlyMemory<byte> data)
162162

163163
private static List<Asn1Element> ReadElements(AsnReader reader)
164164
{
165-
var elements = new List<Asn1Element>();
165+
List<Asn1Element> elements = [];
166166

167167
while (reader.HasData)
168168
{

Src/Fido2/AttestationFormat/FidoU2f.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ .. publicKeyU2F
8585

8686
// 7. Optionally, inspect x5c and consult externally provided knowledge to determine whether attStmt conveys a Basic or AttCA attestation
8787

88-
var trustPath = new X509Certificate2[1] { attCert };
88+
X509Certificate2[] trustPath = [attCert];
8989

9090
return new(new VerifyAttestationResult(AttestationType.AttCa, trustPath));
9191
}

Src/Fido2/Cbor/CborArray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public sealed class CborArray : CborObject, IEnumerable<CborObject>
77
{
88
public CborArray()
99
{
10-
Values = new List<CborObject>();
10+
Values = [];
1111
}
1212

1313
public CborArray(List<CborObject> values)

Src/Fido2/Cbor/CborObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private static CborArray ReadArray(CborReader reader)
8686

8787
var items = count != null
8888
? new List<CborObject>(count.Value)
89-
: new List<CborObject>();
89+
: [];
9090

9191
while (!(reader.PeekState() is CborReaderState.EndArray or CborReaderState.Finished))
9292
{

Src/Fido2/GetAssertionOptionsParams.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public sealed class GetAssertionOptionsParams
2222
///
2323
/// The list is ordered in descending order of preference: the first item in the list is the most preferred credential, and the last is the least preferred.
2424
/// </summary>
25-
public IReadOnlyList<PublicKeyCredentialDescriptor> AllowedCredentials { get; init; } = Array.Empty<PublicKeyCredentialDescriptor>();
25+
public IReadOnlyList<PublicKeyCredentialDescriptor> AllowedCredentials { get; init; } = [];
2626

2727
/// <summary>
2828
/// This OPTIONAL member specifies the Relying Party's requirements regarding user verification for the get() operation. The value SHOULD be a member of UserVerificationRequirement but client platforms MUST ignore unknown values, treating an unknown value as if the member does not exist. Eligible authenticators are filtered to only those capable of satisfying this requirement.

Src/Fido2/Metadata/ConformanceMetadataRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public async Task<MetadataBLOBPayload> GetBLOBAsync(CancellationToken cancellati
8282
Entries = []
8383
};
8484

85-
var entries = new List<MetadataBLOBPayloadEntry>();
85+
List<MetadataBLOBPayloadEntry> entries = [];
8686

8787
foreach (var blobUrl in conformanceEndpoints)
8888
{

0 commit comments

Comments
 (0)