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

Problem with serde impl for k256::ecdsa::VerifyingKey in 0.14.0-pre.2 #1095

Closed
tmpfs opened this issue Oct 17, 2024 · 3 comments
Closed

Problem with serde impl for k256::ecdsa::VerifyingKey in 0.14.0-pre.2 #1095

tmpfs opened this issue Oct 17, 2024 · 3 comments

Comments

@tmpfs
Copy link

tmpfs commented Oct 17, 2024

Seems like the serde derive implementation is not being compiled for k256::ecdsa::VerifyingKey when the serde feature flag is active.

Minimal reproduction:

[package]
name = "k256-serde"
version = "0.1.0"
edition = "2021"

[dependencies]
k256 = { version = "0.14.0-pre.2", default-features = false, features = ["serde", "ecdsa", "std"] }
serde_json = "1"
rand = "0.8"
use k256::ecdsa::SigningKey;
use rand::rngs::OsRng;

fn main() {
    let key = SigningKey::random(&mut OsRng);
    let verifying_key = key.verifying_key();
    serde_json::to_string(verifying_key).unwrap();
}

Yields the compiler error:

error[E0277]: the trait bound `ecdsa::verifying::VerifyingKey<Secp256k1>: serde::ser::Serialize` is not satisfied
    --> src/main.rs:7:27
     |
7    |     serde_json::to_string(verifying_key).unwrap();
     |     --------------------- ^^^^^^^^^^^^^ the trait `serde::ser::Serialize` is not implemented for `ecdsa::verifying::VerifyingKey<Secp256k1>`
     |     |
     |     required by a bound introduced by this call
     |
     = note: for local types consider adding `#[derive(serde::Serialize)]` to your `ecdsa::verifying::VerifyingKey<Secp256k1>` type
     = note: for types from other crates check whether the crate offers a `serde` feature flag
     = help: the following other types implement trait `serde::ser::Serialize`:
               &'a T
               &'a mut T
               ()
               (T,)
               (T0, T1)
               (T0, T1, T2)
               (T0, T1, T2, T3)
               (T0, T1, T2, T3, T4)
             and 142 others
note: required by a bound in `serde_json::to_string`
    --> /Users/muji/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_json-1.0.128/src/ser.rs:2209:17
     |
2207 | pub fn to_string<T>(value: &T) -> Result<String>
     |        --------- required by a bound in this function
2208 | where
2209 |     T: ?Sized + Serialize,
     |                 ^^^^^^^^^ required by this bound in `to_string`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `k256-serde` (bin "k256-serde") due to 1 previous error

Is this an error my end or a problem with propagating the feature flag perhaps?

@tmpfs
Copy link
Author

tmpfs commented Oct 17, 2024

Oh my bad, I noticed I had to enable the pem flag too, is it worth automatically enabling pem when serde is present perhaps?

@tmpfs tmpfs closed this as completed Oct 17, 2024
@tarcieri
Copy link
Member

It's really pkcs8 that's needed, and it could be auto-enabled along with serde, yes

@tarcieri
Copy link
Member

This changes it to work like the elliptic-curve crate, where only the serde feature needs to be enabled: RustCrypto/signatures#874

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

No branches or pull requests

2 participants