Skip to content

Commit 68e5dd7

Browse files
authored
Fix nullable annotations on MLKemAlgorithm and add ToString
1 parent 08758d8 commit 68e5dd7

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/libraries/Common/src/System/Security/Cryptography/MLKemAlgorithm.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,17 @@ private MLKemAlgorithm(
118118
/// <see langword="true" /> if the objects are considered equal; otherwise, <see langword="false" />.
119119
/// </returns>
120120
// This is a closed type, so all we need to compare are the names.
121-
public bool Equals(MLKemAlgorithm? other) => other is not null && other.Name == Name;
121+
public bool Equals([NotNullWhen(true)] MLKemAlgorithm? other) => other is not null && other.Name == Name;
122122

123123
/// <inheritdoc />
124-
public override bool Equals(object? obj) => obj is MLKemAlgorithm alg && alg.Name == Name;
124+
public override bool Equals([NotNullWhen(true)] object? obj) => obj is MLKemAlgorithm alg && alg.Name == Name;
125125

126126
/// <inheritdoc />
127127
public override int GetHashCode() => Name.GetHashCode();
128128

129+
/// <inheritdoc />
130+
public override string ToString() => Name;
131+
129132
/// <summary>
130133
/// Determines whether two <see cref="MLKemAlgorithm" /> objects specify the same algorithm name.
131134
/// </summary>

src/libraries/Common/tests/System/Security/Cryptography/MLKemAlgorithmTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,12 @@ public static void Algorithms_Inquality()
5757
Assert.True(MLKemAlgorithm.MLKem768 != MLKemAlgorithm.MLKem1024, "MLKemAlgorithm.MLKem768 != MLKemAlgorithm.MLKem1024");
5858
Assert.True(MLKemAlgorithm.MLKem1024 != MLKemAlgorithm.MLKem512, "MLKemAlgorithm.MLKem1024 != MLKemAlgorithm.MLKem512");
5959
}
60+
61+
[Theory]
62+
[MemberData(nameof(MLKemTestData.MLKemAlgorithms), MemberType = typeof(MLKemTestData))]
63+
public static void Algorithms_ToString(MLKemAlgorithm algorithm)
64+
{
65+
Assert.Equal(algorithm.Name, algorithm.ToString());
66+
}
6067
}
6168
}

src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,11 +1976,12 @@ internal MLKemAlgorithm() { }
19761976
public string Name { get { throw null; } }
19771977
public int PrivateSeedSizeInBytes { get { throw null; } }
19781978
public int SharedSecretSizeInBytes { get { throw null; } }
1979-
public override bool Equals(object? obj) { throw null; }
1980-
public bool Equals(System.Security.Cryptography.MLKemAlgorithm? other) { throw null; }
1979+
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
1980+
public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Security.Cryptography.MLKemAlgorithm? other) { throw null; }
19811981
public override int GetHashCode() { throw null; }
19821982
public static bool operator ==(System.Security.Cryptography.MLKemAlgorithm? left, System.Security.Cryptography.MLKemAlgorithm? right) { throw null; }
19831983
public static bool operator !=(System.Security.Cryptography.MLKemAlgorithm? left, System.Security.Cryptography.MLKemAlgorithm? right) { throw null; }
1984+
public override string ToString() { throw null; }
19841985
}
19851986
[System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5006", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
19861987
public sealed partial class MLKemOpenSsl : System.Security.Cryptography.MLKem

0 commit comments

Comments
 (0)