Skip to content
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

crypto: serialize keys with alg-prefixed hex strings #261

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

divarvel
Copy link
Collaborator

@divarvel divarvel commented Jan 17, 2025

add from_bytes_string() and to_bytes_string() on PublicKey and PrivateKey, which look like the datalog syntax (ed25519/<hex bytes>), so that the key algorithm is explicit.

This will avoid confusions at program boundaries, when the keys must be read from strings (eg in biscuit-cli or when reading keys from environment variables).

I chose to implement it only on the top level structures (ie not in ed25519 and p256 modules), and in new methods to avoid breaking existing code.

Copy link

codspeed-hq bot commented Jan 17, 2025

CodSpeed Performance Report

Merging #261 will not alter performance

Comparing explicit-key-prefix (e6e2484) with main (f4473ee)

Summary

✅ 12 untouched benchmarks

Copy link

codecov bot commented Jan 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.70%. Comparing base (f4473ee) to head (e6e2484).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #261      +/-   ##
==========================================
+ Coverage   67.39%   67.70%   +0.31%     
==========================================
  Files          39       39              
  Lines        7235     7246      +11     
==========================================
+ Hits         4876     4906      +30     
+ Misses       2359     2340      -19     

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

@divarvel divarvel force-pushed the explicit-key-prefix branch 3 times, most recently from 7adfb06 to eb6def4 Compare January 17, 2025 22:21
Same as for `Display` and `FromStr` impls for `PublicKey`.
`PrivateKey` does not implement `Display` on purpose (to avoid leaking sensitive info in logs), so instead of `to_string()` the method is called `to_prefixed_string()`
it was previously `error::Token` which was way too vague, and gave poor UX when trying to parse a public key
@divarvel divarvel merged commit 8b2b577 into main Jan 27, 2025
7 checks passed
@divarvel divarvel deleted the explicit-key-prefix branch January 27, 2025 07:33
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.

2 participants