Skip to content

Commit aea4b35

Browse files
Copilotgewarren
andcommitted
Add breaking change documentation for CoseSigner.Key property
Co-authored-by: gewarren <[email protected]>
1 parent 0aa7665 commit aea4b35

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

docs/core/compatibility/10.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
5454

5555
| Title | Type of change | Introduced version |
5656
|-------|-------------------|--------------------|
57+
| [CoseSigner.Key may now be null](cryptography/10.0/cosesigner-key-null.md) | Behavioral/source incompatible change | Preview 7 |
5758
| [OpenSSL cryptographic primitives aren't supported on macOS](cryptography/10.0/openssl-macos-unsupported.md) | Behavioral change | Preview 6 |
5859
| [X500DistinguishedName validation is stricter](cryptography/10.0/x500distinguishedname-validation.md) | Behavioral change | Preview 1 |
5960
| [X509Certificate and PublicKey key parameters can be null](cryptography/10.0/x509-publickey-null.md) | Behavioral/source incompatible change | Preview 3 |
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: "Breaking change - CoseSigner.Key may now be null"
3+
description: "Learn about the breaking change in .NET 10 where CoseSigner.Key may now be null when backed by Post-Quantum Cryptography algorithms."
4+
ms.date: 01/25/2025
5+
ai-usage: ai-assisted
6+
ms.custom: https://github.com/dotnet/docs/issues/46999
7+
---
8+
9+
# CoseSigner.Key may now be null
10+
11+
In .NET 10, the <xref:System.Security.Cryptography.Cose.CoseSigner.Key?displayProperty=fullName> property may now return `null`. If `CoseSigner` is backed by an RSA or ECDSA key, then `CoseSigner.Key` continues to return the key and it's non-null. However, when `CoseSigner` is backed by a key that doesn't derive from `AsymmetricAlgorithm`, like `MLDsa` (a new Post-Quantum Cryptography (PQC) signing algorithm), `CoseSigner.Key` returns `null`.
12+
13+
## Version introduced
14+
15+
.NET 10 Preview 7
16+
17+
## Previous behavior
18+
19+
`CoseSigner.Key` couldn't be `null`. It had type `AsymmetricAlgorithm`.
20+
21+
```csharp
22+
using RSA rsaKey = RSA.Create();
23+
CoseSigner signer = new CoseSigner(rsaKey, RSASignaturePadding.Pss, HashAlgorithmName.SHA512);
24+
AsymmetricAlgorithm key = signer.Key; // key was never null
25+
```
26+
27+
## New behavior
28+
29+
`CoseSigner.Key` can be `null`. It now has type `AsymmetricAlgorithm?`.
30+
31+
```csharp
32+
using RSA rsaKey = RSA.Create();
33+
34+
CoseSigner signer = new CoseSigner(rsaKey, RSASignaturePadding.Pss, HashAlgorithmName.SHA512);
35+
// signer.Key is rsaKey here
36+
37+
// CoseKey is a new abstraction for all keys used in COSE
38+
CoseKey coseKey = new CoseKey(rsaKey, RSASignaturePadding.Pss, HashAlgorithmName.SHA512);
39+
signer = new CoseSigner(coseKey);
40+
// signer.Key is rsaKey here
41+
42+
using MLDsa mldsa = MLDsa.GenerateKey(MLDsaAlgorithm.MLDsa44);
43+
44+
coseKey = new CoseKey(mldsa);
45+
signer = new CoseSigner(coseKey);
46+
// signer.Key is null here
47+
```
48+
49+
## Type of breaking change
50+
51+
This is both a [behavioral change](../../categories.md#behavioral-change) and [source compatibility](../../categories.md#source-compatibility) change.
52+
53+
## Reason for change
54+
55+
With the introduction of new signing algorithms such as ML-DSA, .NET has moved away from using `AsymmetricAlgorithm` as the universal base class for all asymmetric algorithms. Likewise, `CoseSigner` can now be constructed with a key that doesn't derive from `AsymmetricAlgorithm`. In this case `CoseSigner.Key` can't return an `AsymmetricAlgorithm` representing the underlying key and thus returns `null` instead.
56+
57+
This change was introduced in <https://github.com/dotnet/runtime/pull/115158>.
58+
59+
## Recommended action
60+
61+
`CoseSigner.Key` can still be used, but callers should handle `null` values.
62+
63+
```csharp
64+
AsymmetricAlgorithm? key = signer.Key;
65+
if (key != null)
66+
{
67+
// Use the key for operations that require AsymmetricAlgorithm
68+
}
69+
else
70+
{
71+
// Handle the case where the signer is backed by a non-AsymmetricAlgorithm key
72+
}
73+
```
74+
75+
## Affected APIs
76+
77+
- <xref:System.Security.Cryptography.Cose.CoseSigner.Key?displayProperty=fullName>

docs/core/compatibility/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ items:
4040
href: core-libraries/10.0/ymm-embedded-rounding.md
4141
- name: Cryptography
4242
items:
43+
- name: CoseSigner.Key may now be null
44+
href: cryptography/10.0/cosesigner-key-null.md
4345
- name: Environment variable renamed to DOTNET_OPENSSL_VERSION_OVERRIDE
4446
href: cryptography/10.0/version-override.md
4547
- name: OpenSSL cryptographic primitives not supported on macOS

0 commit comments

Comments
 (0)