Skip to content
Merged
Show file tree
Hide file tree
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 docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ The PR that reveals the implementation of the `<IncludeInternalObsoleteAttribute
| __`SYSLIB0026`__ | X509Certificate and X509Certificate2 are immutable. Use the appropriate constructor to create a new certificate. |
| __`SYSLIB0027`__ | PublicKey.Key is obsolete. Use the appropriate method to get the public key, such as GetRSAPublicKey. |
| __`SYSLIB0028`__ | X509Certificate2.PrivateKey is obsolete. Use the appropriate method to get the private key, such as GetRSAPrivateKey, or use the CopyWithPrivateKey method to create a new instance with a private key. |
| __`SYSLIB0029`__ | ProduceLegacyHmacValues is obsolete. Producing legacy HMAC values is no longer supported. |
| __`SYSLIB0030`__ | HMACSHA1 always uses the algorithm implementation provided by the platform. Use a constructor without the useManagedSha1 parameter. |

## Analyzer Warnings

Expand Down
6 changes: 6 additions & 0 deletions src/libraries/Common/src/System/Obsoletions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,11 @@ internal static class Obsoletions

internal const string X509CertificatePrivateKeyMessage = "X509Certificate2.PrivateKey is obsolete. Use the appropriate method to get the private key, such as GetRSAPrivateKey, or use the CopyWithPrivateKey method to create a new instance with a private key.";
internal const string X509CertificatePrivateKeyDiagId = "SYSLIB0028";

internal const string ProduceLegacyHmacValuesMessage = "ProduceLegacyHmacValues is obsolete. Producing legacy HMAC values is no longer supported.";
internal const string ProduceLegacyHmacValuesDiagId = "SYSLIB0029";

internal const string UseManagedSha1Message = "HMACSHA1 always uses the algorithm implementation provided by the platform. Use a constructor without the useManagedSha1 parameter.";
internal const string UseManagedSha1DiagId = "SYSLIB0030";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ public partial class HMACSHA1 : System.Security.Cryptography.HMAC
public HMACSHA1() { }
public HMACSHA1(byte[] key) { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("HMACSHA1 always uses the algorithm implementation provided by the platform. Use a constructor without the useManagedSha1 parameter.", DiagnosticId = "SYSLIB0030", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public HMACSHA1(byte[] key, bool useManagedSha1) { }
public override byte[] Key { get { throw null; } set { } }
protected override void Dispose(bool disposing) { }
Expand Down Expand Up @@ -519,6 +520,7 @@ public partial class HMACSHA384 : System.Security.Cryptography.HMAC
public HMACSHA384() { }
public HMACSHA384(byte[] key) { }
public override byte[] Key { get { throw null; } set { } }
[System.ObsoleteAttribute("ProduceLegacyHmacValues is obsolete. Producing legacy HMAC values is no longer supported.", DiagnosticId = "SYSLIB0029", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public bool ProduceLegacyHmacValues { get { throw null; } set { } }
protected override void Dispose(bool disposing) { }
protected override void HashCore(byte[] rgb, int ib, int cb) { }
Expand All @@ -537,6 +539,7 @@ public partial class HMACSHA512 : System.Security.Cryptography.HMAC
public HMACSHA512() { }
public HMACSHA512(byte[] key) { }
public override byte[] Key { get { throw null; } set { } }
[System.ObsoleteAttribute("ProduceLegacyHmacValues is obsolete. Producing legacy HMAC values is no longer supported.", DiagnosticId = "SYSLIB0029", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, surprised we didn't EB-never this.

public bool ProduceLegacyHmacValues { get { throw null; } set { } }
protected override void Dispose(bool disposing) { }
protected override void HashCore(byte[] rgb, int ib, int cb) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Internal.Cryptography;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.Versioning;
Expand Down Expand Up @@ -42,6 +43,7 @@ public HMACSHA1(byte[] key)
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete(Obsoletions.UseManagedSha1Message, DiagnosticId = Obsoletions.UseManagedSha1DiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public HMACSHA1(byte[] key, bool useManagedSha1) : this(key)
{
// useManagedSha1 is ignored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Internal.Cryptography;
using System;
using System.Diagnostics;
using System.Runtime.Versioning;
using System.Security.Cryptography;
Expand Down Expand Up @@ -40,6 +41,7 @@ public HMACSHA384(byte[] key)
Debug.Assert(HashSizeValue == HmacSizeBits);
}

[Obsolete(Obsoletions.ProduceLegacyHmacValuesMessage, DiagnosticId = Obsoletions.ProduceLegacyHmacValuesDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public bool ProduceLegacyHmacValues
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Internal.Cryptography;
using System;
using System.Diagnostics;
using System.Runtime.Versioning;
using System.Security.Cryptography;
Expand Down Expand Up @@ -39,6 +40,7 @@ public HMACSHA512(byte[] key)
HashSizeValue = _hMacCommon.HashSizeInBits;
}

[Obsolete(Obsoletions.ProduceLegacyHmacValuesMessage, DiagnosticId = Obsoletions.ProduceLegacyHmacValuesDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
public bool ProduceLegacyHmacValues
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,18 @@ public void HmacSha1_Byte_Constructors()
using (HMACSHA1 h1 = new HMACSHA1(key))
{
VerifyHmac_KeyAlreadySet(h1, 1, digest);
using (HMACSHA1 h2 = new HMACSHA1(key, true))
#pragma warning disable SYSLIB0030 // useManagedSha1 is obsolete
using (HMACSHA1 h2 = new HMACSHA1(key, useManagedSha1: true))
{
VerifyHmac_KeyAlreadySet(h2, 1, digest);
Assert.Equal(h1.Key, h2.Key);
}
using (HMACSHA1 h2 = new HMACSHA1(key, false))
using (HMACSHA1 h2 = new HMACSHA1(key, useManagedSha1: false))
{
VerifyHmac_KeyAlreadySet(h1, 1, digest);
Assert.Equal(h1.Key, h2.Key);
}
#pragma warning restore SYSLIB0030
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public void ProduceLegacyHmacValues()
{
using (var h = new HMACSHA384())
{
#pragma warning disable SYSLIB0029 // ProduceLegacyHmacValues is obsolete
Assert.False(h.ProduceLegacyHmacValues);
h.ProduceLegacyHmacValues = false; // doesn't throw
Assert.Throws<PlatformNotSupportedException>(() => h.ProduceLegacyHmacValues = true);
#pragma warning restore SYSLIB0029
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public void ProduceLegacyHmacValues()
{
using (var h = new HMACSHA512())
{
#pragma warning disable SYSLIB0029 // ProduceLegacyHmacValues is obsolete
Assert.False(h.ProduceLegacyHmacValues);
h.ProduceLegacyHmacValues = false; // doesn't throw
Assert.Throws<PlatformNotSupportedException>(() => h.ProduceLegacyHmacValues = true);
#pragma warning restore SYSLIB0029
}
}

Expand Down