-
Notifications
You must be signed in to change notification settings - Fork 6k
Add breaking change documentation for CoseSigner.Key property nullability #47740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0aa7665
Initial plan
Copilot aea4b35
Add breaking change documentation for CoseSigner.Key property
Copilot 07c5c79
Apply suggestions from code review
gewarren be939c8
Update date
gewarren 34f3739
Update docs/core/compatibility/cryptography/10.0/cosesigner-key-null.md
gewarren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
docs/core/compatibility/cryptography/10.0/cosesigner-key-null.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
title: "Breaking change - CoseSigner.Key may now be null" | ||
description: "Learn about the breaking change in .NET 10 where CoseSigner.Key may now be null when backed by Post-Quantum Cryptography algorithms." | ||
ms.date: 01/25/2025 | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
ai-usage: ai-assisted | ||
ms.custom: https://github.com/dotnet/docs/issues/46999 | ||
--- | ||
|
||
# CoseSigner.Key may now be null | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
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`. | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Version introduced | ||
|
||
.NET 10 Preview 7 | ||
|
||
## Previous behavior | ||
|
||
`CoseSigner.Key` couldn't be `null`. It had type `AsymmetricAlgorithm`. | ||
|
||
```csharp | ||
using RSA rsaKey = RSA.Create(); | ||
CoseSigner signer = new CoseSigner(rsaKey, RSASignaturePadding.Pss, HashAlgorithmName.SHA512); | ||
AsymmetricAlgorithm key = signer.Key; // key was never null | ||
``` | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## New behavior | ||
|
||
`CoseSigner.Key` can be `null`. It now has type `AsymmetricAlgorithm?`. | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```csharp | ||
using RSA rsaKey = RSA.Create(); | ||
|
||
CoseSigner signer = new CoseSigner(rsaKey, RSASignaturePadding.Pss, HashAlgorithmName.SHA512); | ||
// signer.Key is rsaKey here | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// CoseKey is a new abstraction for all keys used in COSE | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
CoseKey coseKey = new CoseKey(rsaKey, RSASignaturePadding.Pss, HashAlgorithmName.SHA512); | ||
signer = new CoseSigner(coseKey); | ||
// signer.Key is rsaKey here | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
using MLDsa mldsa = MLDsa.GenerateKey(MLDsaAlgorithm.MLDsa44); | ||
|
||
coseKey = new CoseKey(mldsa); | ||
signer = new CoseSigner(coseKey); | ||
// signer.Key is null here | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
``` | ||
|
||
## Type of breaking change | ||
|
||
This is both a [behavioral change](../../categories.md#behavioral-change) and [source compatibility](../../categories.md#source-compatibility) change. | ||
PranavSenthilnathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Reason for change | ||
|
||
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. | ||
|
||
This change was introduced in <https://github.com/dotnet/runtime/pull/115158>. | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Recommended action | ||
|
||
`CoseSigner.Key` can still be used, but callers should handle `null` values. | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
```csharp | ||
AsymmetricAlgorithm? key = signer.Key; | ||
if (key != null) | ||
{ | ||
// Use the key for operations that require AsymmetricAlgorithm | ||
} | ||
else | ||
{ | ||
// Handle the case where the signer is backed by a non-AsymmetricAlgorithm key | ||
} | ||
``` | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
## Affected APIs | ||
|
||
- <xref:System.Security.Cryptography.Cose.CoseSigner.Key?displayProperty=fullName> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.