RustCrypto / elliptic-curves

Collection of pure Rust elliptic curve implementations: NIST P-224, P-256, P-384, P-521, secp256k1, SM2
678 stars 189 forks source link

[k256] Build error: `struct Secp256k1` doesn't implement `AssociatedOid` #1098

Open matthiasgeihs opened 4 days ago

matthiasgeihs commented 4 days ago

I work on a project using k256 = 0.13.4 with features = ["arithmetic", "hash2curve", "schnorr", "serde"] and default-features = false. The project fails to build with the following error:

% cargo build --release
   Compiling k256 v0.13.4
error[E0599]: the method `serialize` exists for struct `PublicKey<Secp256k1>`, but its trait bounds were not satisfied
   --> /Users/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/k256-0.13.4/src/schnorr/verifying.rs:171:20
    |
171 |         self.inner.serialize(serializer)
    |                    ^^^^^^^^^ method cannot be called on `PublicKey<Secp256k1>` due to unsatisfied trait bounds
    |
   ::: /Users/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/k256-0.13.4/src/lib.rs:89:1
    |
89  | pub struct Secp256k1;
    | -------------------- doesn't satisfy `Secp256k1: AssociatedOid`
    |
   ::: /Users/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/elliptic-curve-0.13.8/src/public_key.rs:90:1
    |
90  | pub struct PublicKey<C>
    | ----------------------- doesn't satisfy `elliptic_curve::PublicKey<Secp256k1>: Serialize`
    |
    = note: the following trait bounds were not satisfied:
            `Secp256k1: AssociatedOid`
            which is required by `elliptic_curve::PublicKey<Secp256k1>: Serialize`
note: the trait `AssociatedOid` must be implemented
   --> /Users/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/const-oid-0.9.6/src/lib.rs:44:1
    |
44  | pub trait AssociatedOid {
    | ^^^^^^^^^^^^^^^^^^^^^^^

The problem seems to be that feature "pkcs8" is required when "schnorr" and "serde" are enabled. This cost me a bit of time to realize. Is there a better way to setup the project so that this error does not occur? Or at least a more helpful error message would be nice. Maybe feature "serde" should require "pkcs8"?

tarcieri commented 4 days ago

Yeah, elsewhere we transitively activate pkcs8 when the serde feature is enabled (e.g. in the elliptic-curve and ecdsa crates). k256 should probably be updated to do the same (it wasn't really possible, or rather would be quite convoluted without weak/namespaced features, which k256 predates)