Skip to content

fix(proto): improve unsupported key and algorithm error messages - #603

Merged
yizha1 merged 1 commit into
notaryproject:mainfrom
cshung:users/yinghungau/error-messages
Nov 30, 2026
Merged

yizha1 merged 1 commit into
notaryproject:mainfrom
cshung:users/yinghungau/error-messages

Conversation

@cshung

@cshung cshung commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Summary

The error paths in EncodeKeySpec, HashAlgorithmFromKeySpec, and EncodeSigningAlgorithm format integer-backed values with %q. This renders rejected key types, key sizes, and algorithm IDs as Unicode characters rather than meaningful diagnostic values. For example, an RSA key with size 1234 produces invalid KeySpec {'\x01' 'Ӓ'}.

This change reports named RSA/EC key types and labeled sizes in bits, with decimal values for unknown key types and signing algorithms:

unsupported key specification: type=RSA, size=1234 bits
unsupported key specification: type=99, size=2048 bits
unsupported signing algorithm: 1234

Both key-specification conversion functions share the error formatting. Tests assert the diagnostic messages for unsupported RSA/EC sizes, unknown key types, zero values, and unknown algorithms, while retaining the existing supported-conversion cases.

This intentionally changes error text, but does not change accepted inputs or successful return values. No dependencies or registry mocks are changed.

Motivation

This is a pre-existing formatting bug exposed by the Go 1.26 vet checks when the module declares Go 1.26, as proposed in #598. The same character-formatted output was reproduced with Go 1.23, 1.24, and 1.26. The repair is independent of the ORAS upgrade and works with the existing Go 1.23 minimum and ORAS 2.6.0 dependency.

Related: #598.

Validation

  • Go 1.23.0: full uncached race-enabled SDK suite with coverage passed.
  • Go 1.24.0: uncached race-enabled ./plugin/proto tests passed.
  • Go 1.26.0: go vet ./... passed.
  • Formatting and git diff --check passed.

These are local results; PR CI will provide the upstream checks.

Integer-backed key types, key sizes, and signing algorithms were formatted
with %q, causing rejected values to appear as Unicode characters rather
than useful diagnostics.

Name RSA and EC key types, label key sizes in bits, and retain decimal
values for unknown key types and signing algorithms. Share key-specification
error formatting between both conversion functions.

Add assertions for supported conversions and error messages for unsupported
key sizes, unknown key types, and unknown signing algorithms. Accepted
inputs and returned values are unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3a297bdb-d8ae-492d-bae7-d555afa73630
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 30, 2026 18:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the clearer key and algorithm diagnostics and accompanying test updates.

No open issues 🎉

What changed in this PR

This PR improves diagnostics for unsupported keys and signing algorithms in the plugin protocol conversion layer, without changing accepted inputs or successful return values. The fix is independent of the dependency upgrade in #598.

Changes:

  • Share key-specification error formatting with readable RSA/EC names, decimal unknown types, and sizes labeled in bits; report unsupported algorithm IDs in decimal.
  • Extend tests to assert exact error messages for invalid inputs and confirm supported conversions return no errors.
File Description
plugin/​proto/​algorithm.go Replaces character-formatted errors with readable key and algorithm diagnostics.
plugin/​proto/​algorithm_test.go Adds error assertions for unsupported sizes, unknown types and algorithms, and zero values.

Review effort: Balanced

@yizha1 yizha1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thanks @cshung

@yizha1
yizha1 merged commit 04c85a3 into notaryproject:main Nov 30, 2026
7 checks passed
@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.94%. Comparing base (860dedc) to head (faad9e0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #603      +/-   ##
==========================================
+ Coverage   82.88%   82.94%   +0.06%     
==========================================
  Files          36       36              
  Lines        2635     2645      +10     
==========================================
+ Hits         2184     2194      +10     
  Misses        310      310              
  Partials      141      141              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cshung
cshung deleted the users/yinghungau/error-messages branch November 30, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants