Skip to content

Commit a9ebfb9

Browse files
Resolve some compilation warnings
1 parent 4682a07 commit a9ebfb9

37 files changed

Lines changed: 168 additions & 147 deletions

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ dotnet_naming_symbols.constant_fields.required_modifiers = const
7272
###############################
7373
# CA1051: Do not declare visible instance fields
7474
dotnet_code_quality.ca1051.api_surface = public
75+
# CA1819: Properties should not return arrays (suppressed due to heavy interop code use)
76+
dotnet_diagnostic.CA1819.severity = none
7577
###############################
7678
# C# Coding Conventions #
7779
###############################

Src/DSInternals.Win32.WebAuthn.Adapter.Tests/WebAuthnApiAdapterTester.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void WebAuthN_GetAssertion_Cancel()
181181

182182
var webauthn = new WebAuthnApiAdapter();
183183

184-
var source = new CancellationTokenSource(5000); // Cancel in 5 seconds
184+
using var source = new CancellationTokenSource(5000); // Cancel in 5 seconds
185185
Assert.ThrowsExactly<OperationCanceledException>(() =>
186186
webauthn.AuthenticatorGetAssertionAsync(options, null, source.Token).GetAwaiter().GetResult());
187187
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#if !NET9_0_OR_GREATER
2+
using System;
3+
4+
namespace System.Security.Cryptography.X509Certificates;
5+
6+
/// <summary>
7+
/// Provides compatibility members for APIs added to newer .NET versions.
8+
/// </summary>
9+
public static class X509CertificateLoader
10+
{
11+
/// <summary>
12+
/// Loads an X.509 certificate from raw DER/BER encoded bytes.
13+
/// </summary>
14+
/// <param name="data">The raw certificate bytes.</param>
15+
/// <returns>The loaded certificate.</returns>
16+
public static X509Certificate2 LoadCertificate(byte[] data)
17+
{
18+
ArgumentNullException.ThrowIfNull(data);
19+
return new X509Certificate2(data);
20+
}
21+
}
22+
#endif

Src/DSInternals.Win32.WebAuthn/Interop/Marshalers/AuthenticatorDetailsListSafeHandle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protected override bool ReleaseHandle()
1313
return true;
1414
}
1515

16-
internal AuthenticatorDetailsOut[] ToManaged()
16+
internal AuthenticatorDetailsOut[]? ToManaged()
1717
{
1818
if (this.IsInvalid)
1919
{

Src/DSInternals.Win32.WebAuthn/Interop/Marshalers/ByteArray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace DSInternals.Win32.WebAuthn.Interop
77
[StructLayout(LayoutKind.Sequential)]
88
internal class ByteArrayOut
99
{
10-
protected IntPtr _nativeArray = IntPtr.Zero;
10+
protected IntPtr _nativeArray;
1111

1212
// This class is only created by marshaling.
1313
protected ByteArrayOut() { }

Src/DSInternals.Win32.WebAuthn/Interop/Marshalers/CredentialAttestationSafeHandle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected override bool ReleaseHandle()
1515
return true;
1616
}
1717

18-
internal CredentialAttestation ToManaged()
18+
internal CredentialAttestation? ToManaged()
1919
{
2020
if (this.IsInvalid)
2121
{

Src/DSInternals.Win32.WebAuthn/Interop/Marshalers/PlatformCredentialListSafeHandle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected override bool ReleaseHandle()
1414
return true;
1515
}
1616

17-
internal CredentialDetailsOut[] ToManaged()
17+
internal CredentialDetailsOut[]? ToManaged()
1818
{
1919
return Marshal.PtrToStructure<CredentialDetailsList>(handle)?.Items;
2020
}

Src/DSInternals.Win32.WebAuthn/Interop/Marshalers/SafeStringArray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace DSInternals.Win32.WebAuthn.Interop
77
internal class SafeStringArrayIn : IDisposable
88
{
99
protected int _length;
10-
protected IntPtr _nativeArray = IntPtr.Zero;
10+
protected IntPtr _nativeArray;
1111

1212
public SafeStringArrayIn(string[]? items)
1313
{

Src/DSInternals.Win32.WebAuthn/Interop/Marshalers/SafeStructArray.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace DSInternals.Win32.WebAuthn.Interop
77
internal abstract class SafeStructArrayOut<T>
88
{
99
protected int _length;
10-
protected IntPtr _nativeArray = IntPtr.Zero;
10+
protected IntPtr _nativeArray;
1111

1212
protected SafeStructArrayOut()
1313
{
@@ -42,7 +42,7 @@ public T[]? Items
4242
internal abstract class SafeStructArrayIn<T> : IDisposable
4343
{
4444
protected int _length;
45-
protected IntPtr _nativeArray = IntPtr.Zero;
45+
protected IntPtr _nativeArray;
4646

4747
public SafeStructArrayIn(T[]? items)
4848
{

Src/DSInternals.Win32.WebAuthn/Interop/Marshalers/VersionedStructMarshaler.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@ namespace DSInternals.Win32.WebAuthn.Interop
55
{
66
internal static class VersionedStructMarshaler
77
{
8-
public static T PtrToStructure<T>(IntPtr ptr, int sourceStructSize) where T : class
8+
public static T? PtrToStructure<T>(IntPtr ptr, int sourceStructSize) where T : class
99
{
1010
if (ptr == IntPtr.Zero || sourceStructSize == 0)
1111
{
1212
return null;
1313
}
1414

15-
if (sourceStructSize < 0)
16-
{
17-
throw new ArgumentOutOfRangeException(nameof(sourceStructSize));
18-
}
15+
ArgumentOutOfRangeException.ThrowIfNegative(sourceStructSize);
1916

2017
int targetStructSize = Marshal.SizeOf<T>();
2118

0 commit comments

Comments
 (0)