Skip to content

Commit

Permalink
[Models] Enable nullable (2 of 2) (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcarbon authored Jan 10, 2025
1 parent b7f1735 commit b6102f0
Show file tree
Hide file tree
Showing 30 changed files with 78 additions and 54 deletions.
2 changes: 2 additions & 0 deletions Src/Fido2.Models/AssertionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions Src/Fido2.Models/AuthenticatorAssertionRawResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public AuthenticationExtensionsClientOutputs Extensions
[JsonPropertyName("clientExtensionResults"), Required]
public AuthenticationExtensionsClientOutputs ClientExtensionResults { get; set; }

#nullable enable

public sealed class AssertionResponse
{
[JsonConverter(typeof(Base64UrlConverter))]
Expand All @@ -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; }
Expand Down
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;
Expand Down
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;
Expand Down
4 changes: 2 additions & 2 deletions Src/Fido2.Models/Converters/EnumNameMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Src/Fido2.Models/Converters/FidoEnumConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions Src/Fido2.Models/CredentialCreateOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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,
Expand All @@ -122,7 +125,7 @@ public static CredentialCreateOptions Create(
AuthenticatorSelection authenticatorSelection,
AttestationConveyancePreference attestationConveyancePreference,
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
AuthenticationExtensionsClientInputs extensions,
AuthenticationExtensionsClientInputs? extensions,
IReadOnlyList<PubKeyCredParam> pubKeyCredParams)

{
Expand All @@ -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>
Expand Down
1 change: 1 addition & 0 deletions Src/Fido2.Models/Fido2.Models.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<RootNamespace>Fido2NetLib</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsTrimmable>true</IsTrimmable>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<IsPackable>true</IsPackable>
</PropertyGroup>
Expand Down
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;

Expand Down
10 changes: 5 additions & 5 deletions Src/Fido2.Models/Metadata/BiometricStatusReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Up @@ -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>
Expand Down
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;

Expand All @@ -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.
Expand Down
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;
Expand Down
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;
Expand Down
2 changes: 1 addition & 1 deletion Src/Fido2.Models/Metadata/RgbPaletteEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
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;
Expand Down
2 changes: 1 addition & 1 deletion Src/Fido2.Models/Metadata/UafVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
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;

Expand Down
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;

Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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;

Expand Down
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;

Expand Down
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;

Expand Down
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;

Expand Down
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;

Expand Down
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;

Expand Down
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;

Expand Down
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;

Expand Down
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
Expand Down
3 changes: 2 additions & 1 deletion Src/Fido2/Metadata/ConformanceMetadataRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down

0 comments on commit b6102f0

Please sign in to comment.