Skip to content

Conversation

@vcsjones
Copy link
Member

The ToBeSignedBuilder for hash and pure modes had an Append that accepts a ReadOnlySpan. For .NET Framework and .NET Standard, IncrementalHash and MemoryStream cannot operate on a ReadOnlySpan, so they were getting converted to an array again. There were a number of places where we already had an array though.

This change avoids to array to span to array conversation by introducing a new AppendToBeSigned overload that accepts an array with an offset and length, which avoids a ToArray().

The ToBeSignedBuilder for hash and pure modes had an Append that accepts a ReadOnlySpan. For .NET Framework and .NET Standard, IncrementalHash and MemoryStream cannot operate on a ReadOnlySpan, so they were getting converted to an array again. There were a number of places where we already had an array though.

This change avoids to array to span to array conversation by introducing a new AppendToBeSigned overload that accepts an array with an offset and length, which avoids a ToArray().
@vcsjones vcsjones added this to the 11.0.0 milestone Nov 12, 2025
@vcsjones vcsjones self-assigned this Nov 12, 2025
Copilot AI review requested due to automatic review settings November 12, 2025 16:48
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

Copilot finished reviewing on behalf of vcsjones November 12, 2025 16:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes performance for COSE signing operations by avoiding unnecessary array allocations on .NET Framework and .NET Standard 2.0. The optimization introduces a new AppendToBeSigned overload that accepts array-based parameters (byte[], offset, length) to avoid converting arrays to spans and back to arrays.

  • Adds new array-based AppendToBeSigned overload to avoid redundant conversions
  • Updates call sites that already have byte arrays to use the new overload
  • Maintains the existing ReadOnlySpan<byte> overload for stack-allocated buffers

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
ToBeSignedBuilder.cs Adds abstract method declaration for array-based AppendToBeSigned overload
PureDataToBeSignedBuilder.cs Implements array-based AppendToBeSigned using MemoryStream.Write
HashToBeSignedBuilder.cs Implements array-based AppendToBeSigned using IncrementalHash.AppendData
CoseMessage.cs Updates three call sites to use the new array-based overload where byte arrays are already available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant