Skip to content
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

[Models] Enable nullable (2 of 2) #585

Merged
merged 1 commit into from
Jan 10, 2025
Merged
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
2 changes: 2 additions & 0 deletions Src/Fido2.Models/AssertionOptions.cs
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@ namespace Fido2NetLib;
/// </summary>
public class AssertionOptions
{
#nullable disable

/// <summary>
/// This member represents a challenge that the selected authenticator signs, along with other data, when producing an authentication assertion.
/// See the §13.1 Cryptographic Challenges security consideration.
4 changes: 2 additions & 2 deletions Src/Fido2.Models/AuthenticatorAssertionRawResponse.cs
Original file line number Diff line number Diff line change
@@ -38,6 +38,8 @@ public AuthenticationExtensionsClientOutputs Extensions
[JsonPropertyName("clientExtensionResults"), Required]
public AuthenticationExtensionsClientOutputs ClientExtensionResults { get; set; }

#nullable enable

public sealed class AssertionResponse
{
[JsonConverter(typeof(Base64UrlConverter))]
@@ -52,8 +54,6 @@ public sealed class AssertionResponse
[JsonPropertyName("clientDataJSON")]
public required byte[] ClientDataJson { get; init; }

#nullable enable

[JsonPropertyName("userHandle")]
[JsonConverter(typeof(Base64UrlConverter))]
public byte[]? UserHandle { get; init; }
4 changes: 3 additions & 1 deletion Src/Fido2.Models/AuthenticatorAttestationRawResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.ComponentModel.DataAnnotations;
#nullable disable

using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

using Fido2NetLib.Objects;
4 changes: 1 addition & 3 deletions Src/Fido2.Models/Converters/Base64UrlConverter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#nullable enable

using System.Buffers;
using System.Buffers;
using System.Buffers.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
4 changes: 2 additions & 2 deletions Src/Fido2.Models/Converters/EnumNameMapper.cs
Original file line number Diff line number Diff line change
@@ -47,9 +47,9 @@ private static FrozenDictionary<TEnum, string> GetIdToNameMap()
{
var description = field.GetCustomAttribute<EnumMemberAttribute>(false);

var value = (TEnum)field.GetValue(null);
var value = (TEnum)field.GetValue(null)!;

items.Add(new(value, description is not null ? description.Value : value.ToString()));
items.Add(new(value, description is not null ? description.Value! : value.ToString()));
}

return items.ToFrozenDictionary();
2 changes: 1 addition & 1 deletion Src/Fido2.Models/Converters/FidoEnumConverter.cs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerial
switch (reader.TokenType)
{
case JsonTokenType.String:
string text = reader.GetString();
string text = reader.GetString()!;
if (EnumNameMapper<T>.TryGetValue(text, out T value))
return value;
else
13 changes: 7 additions & 6 deletions Src/Fido2.Models/CredentialCreateOptions.cs
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ namespace Fido2NetLib;
public sealed class CredentialCreateOptions
{
/// <summary>
///
/// This member contains data about the Relying Party responsible for the request.
/// Its value’s name member is required.
/// Its value’s id member specifies the relying party identifier with which the credential should be associated.If omitted, its value will be the CredentialsContainer object’s relevant settings object's origin's effective domain.
@@ -58,12 +57,16 @@ public sealed class CredentialCreateOptions
[JsonPropertyName("attestationFormats")]
public IReadOnlyList<AttestationStatementFormatIdentifier> AttestationFormats { get; set; } = [];

#nullable disable

/// <summary>
/// This member is intended for use by Relying Parties that wish to select the appropriate authenticators to participate in the create() operation.
/// </summary>
[JsonPropertyName("authenticatorSelection")]
public AuthenticatorSelection AuthenticatorSelection { get; set; }

#nullable enable

private IReadOnlyList<PublicKeyCredentialHint> _hints = Array.Empty<PublicKeyCredentialHint>();

/// <summary>
@@ -113,7 +116,7 @@ public IReadOnlyList<PublicKeyCredentialHint> Hints
/// </summary>
[JsonPropertyName("extensions")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public AuthenticationExtensionsClientInputs Extensions { get; set; }
public AuthenticationExtensionsClientInputs? Extensions { get; set; }

public static CredentialCreateOptions Create(
Fido2Configuration config,
@@ -122,7 +125,7 @@ public static CredentialCreateOptions Create(
AuthenticatorSelection authenticatorSelection,
AttestationConveyancePreference attestationConveyancePreference,
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
AuthenticationExtensionsClientInputs extensions,
AuthenticationExtensionsClientInputs? extensions,
IReadOnlyList<PubKeyCredParam> pubKeyCredParams)

{
@@ -147,12 +150,10 @@ public string ToJson()

public static CredentialCreateOptions FromJson(string json)
{
return JsonSerializer.Deserialize(json, FidoModelSerializerContext.Default.CredentialCreateOptions);
return JsonSerializer.Deserialize(json, FidoModelSerializerContext.Default.CredentialCreateOptions)!;
}
}

#nullable enable

/// <summary>
/// Constructs a PubKeyCredParam instance
/// </summary>
1 change: 1 addition & 0 deletions Src/Fido2.Models/Fido2.Models.csproj
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
<RootNamespace>Fido2NetLib</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsTrimmable>true</IsTrimmable>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<IsPackable>true</IsPackable>
</PropertyGroup>
4 changes: 3 additions & 1 deletion Src/Fido2.Models/Fido2Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Runtime.Serialization;
#nullable disable

using System.Runtime.Serialization;

namespace Fido2NetLib;

10 changes: 5 additions & 5 deletions Src/Fido2.Models/Metadata/BiometricStatusReport.cs
Original file line number Diff line number Diff line change
@@ -31,19 +31,19 @@ public class BiometricStatusReport
/// <para>If no date is given, the status is assumed to be effective while present.</para>
/// </summary>
[JsonPropertyName("effectiveDate")]
public string EffectiveDate { get; set; }
public string? EffectiveDate { get; set; }

/// <summary>
/// Gets or sets the externally visible aspects of the Biometric Certification evaluation.
/// </summary>
[JsonPropertyName("certificationDescriptor")]
public string CertificationDescriptor { get; set; }
public string? CertificationDescriptor { get; set; }

/// <summary>
/// Gets or sets the unique identifier for the issued Biometric Certification.
/// </summary>
[JsonPropertyName("certificateNumber")]
public string CertificateNumber { get; set; }
public string? CertificateNumber { get; set; }

/// <summary>
/// Gets or sets the version of the Biometric Certification Policy the implementation is Certified to.
@@ -52,7 +52,7 @@ public class BiometricStatusReport
/// For example: "1.0.0".
/// </remarks>
[JsonPropertyName("certificationPolicyVersion")]
public string CertificationPolicyVersion { get; set; }
public string? CertificationPolicyVersion { get; set; }

/// <summary>
/// Gets or sets the version of the Biometric Requirements the implementation is certified to.
@@ -61,5 +61,5 @@ public class BiometricStatusReport
/// For example: "1.0.0".
/// </remarks>
[JsonPropertyName("certificationRequirementsVersion")]
public string CertificationRequirementsVersion { get; set; }
public string? CertificationRequirementsVersion { get; set; }
}
Original file line number Diff line number Diff line change
@@ -52,6 +52,8 @@ public sealed class DisplayPNGCharacteristicsDescriptor
[JsonPropertyName("interlace")]
public required byte Interlace { get; set; }

#nullable disable

/// <summary>
/// Gets or sets the palette (1 to 256 palette entries).
/// </summary>
19 changes: 10 additions & 9 deletions Src/Fido2.Models/Metadata/MetadataBLOBPayload.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace Fido2NetLib;

@@ -18,28 +17,30 @@ public sealed class MetadataBLOBPayload
/// This value MAY contain URL(s) pointing to further information, such as a full Terms and Conditions statement.
/// </remarks>
[JsonPropertyName("legalHeader")]
public string LegalHeader { get; set; }
public string? LegalHeader { get; set; }

/// <summary>
/// Gets or sets the serial number of this UAF Metadata BLOB Payload.
/// </summary>
/// <remarks>
/// Serial numbers MUST be consecutive and strictly monotonic, i.e. the successor BLOB will have a no value exactly incremented by one.
/// </remarks>
[JsonPropertyName("no"), Required]
public int Number { get; set; }
[JsonPropertyName("no")]
public required int Number { get; set; }

/// <summary>
/// Gets or sets a formatted date (ISO-8601) when the next update will be provided at latest.
/// </summary>
[JsonPropertyName("nextUpdate"), Required]
public string NextUpdate { get; set; }
[JsonPropertyName("nextUpdate")]
public required string NextUpdate { get; set; }

/// <summary>
/// Gets or sets a list of zero or more entries of <see cref="MetadataBLOBPayloadEntry"/>.
/// </summary>
[JsonPropertyName("entries"), Required]
public MetadataBLOBPayloadEntry[] Entries { get; set; }
[JsonPropertyName("entries")]
public required MetadataBLOBPayloadEntry[] Entries { get; set; }

#nullable disable

/// <summary>
/// The "alg" property from the original JWT header. Used to validate MetadataStatements.
4 changes: 3 additions & 1 deletion Src/Fido2.Models/Metadata/MetadataBLOBPayloadEntry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.ComponentModel.DataAnnotations;
#nullable disable

using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace Fido2NetLib;
4 changes: 3 additions & 1 deletion Src/Fido2.Models/Metadata/MetadataStatement.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.ComponentModel.DataAnnotations;
#nullable disable

using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace Fido2NetLib;
2 changes: 1 addition & 1 deletion Src/Fido2.Models/Metadata/RgbPaletteEntry.cs
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ public bool Equals(RgbPaletteEntry other)
&& B == other.B;
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return obj is RgbPaletteEntry other && Equals(other);
}
4 changes: 3 additions & 1 deletion Src/Fido2.Models/Metadata/StatusReport.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.ComponentModel.DataAnnotations;
#nullable disable

using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;

namespace Fido2NetLib;
2 changes: 1 addition & 1 deletion Src/Fido2.Models/Metadata/UafVersion.cs
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ public bool Equals(UafVersion other)
&& Minor == other.Minor;
}

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return obj is UafVersion other && Equals(other);
}
4 changes: 3 additions & 1 deletion Src/Fido2.Models/Metadata/VerificationMethodDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Text.Json.Serialization;
#nullable disable

using System.Text.Json.Serialization;

namespace Fido2NetLib;

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Text.Json.Serialization;
#nullable disable

using System.Text.Json.Serialization;

namespace Fido2NetLib.Objects;

@@ -40,6 +42,7 @@ public sealed class AuthenticationExtensionsClientInputs
public bool? UserVerificationMethod { private get; set; }

#nullable enable

/// <summary>
/// This client registration extension facilitates reporting certain credential properties known by the client to the requesting WebAuthn Relying Party upon creation of a public key credential source as a result of a registration ceremony.
/// </summary>
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@ public class AuthenticationExtensionsClientOutputs
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public bool? Example { get; set; }

#nullable enable

/// <summary>
/// This extension allows WebAuthn Relying Parties that have previously registered a credential using the legacy FIDO JavaScript APIs to request an assertion.
/// https://www.w3.org/TR/webauthn/#sctn-appid-extension
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace Fido2NetLib.Objects;

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace Fido2NetLib.Objects;

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Text.Json.Serialization;
#nullable disable

using System.Text.Json.Serialization;

namespace Fido2NetLib.Objects;

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Text.Json.Serialization;
#nullable disable

using System.Text.Json.Serialization;

namespace Fido2NetLib.Objects;

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#nullable enable

using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace Fido2NetLib.Objects;

3 changes: 1 addition & 2 deletions Src/Fido2.Models/Objects/CredentialPropertiesOutput.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;

namespace Fido2NetLib.Objects;

4 changes: 3 additions & 1 deletion Src/Fido2.Models/Objects/PublicKeyCredentialUserEntity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.ComponentModel.DataAnnotations;
#nullable disable

using System.ComponentModel.DataAnnotations;

namespace Fido2NetLib.Objects;

4 changes: 3 additions & 1 deletion Src/Fido2.Models/Objects/RegisteredPublicKeyCredential.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Text.Json.Serialization;
#nullable disable

using System.Text.Json.Serialization;

namespace Fido2NetLib.Objects;

4 changes: 3 additions & 1 deletion Src/Fido2.Models/Objects/VerifyAssertionResult.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Fido2NetLib.Objects;
#nullable disable

namespace Fido2NetLib.Objects;

/// <summary>
/// Result of the MakeAssertion verification
3 changes: 2 additions & 1 deletion Src/Fido2/Metadata/ConformanceMetadataRepository.cs
Original file line number Diff line number Diff line change
@@ -78,7 +78,8 @@ public async Task<MetadataBLOBPayload> GetBLOBAsync(CancellationToken cancellati
var combinedBlob = new MetadataBLOBPayload
{
Number = -1,
NextUpdate = "2099-08-07"
NextUpdate = "2099-08-07",
Entries = []
};

var entries = new List<MetadataBLOBPayloadEntry>();
Loading