feat: split cose and jwt into independent default-on features#56
Closed
imlk0 wants to merge 1 commit into
Closed
Conversation
imlk0
force-pushed
the
feature-guard
branch
2 times, most recently
from
July 14, 2026 08:04
178e58c to
73a6c89
Compare
Xynnn007
reviewed
Jul 14, 2026
Make cose-rust, openssl, and jsonwebtoken optional behind two independent default-on features: cose = [dep:cose-rust, dep:openssl, dep:jsonwebtoken] jwt = [dep:jsonwebtoken] cose no longer implies the jwt feature -- it depends on the jsonwebtoken *crate* (used by from_cose_jwk to parse JWK keys), not the jwt feature's API surface. This lets JWT-only builds drop cose+openssl and COSE-only builds drop the jwt feature's code, with the two features genuinely orthogonal. The jsonwebtoken import in ear.rs is now gated on any(cose, jwt) so the shared JWK types are available to the cose path without forcing the jwt feature on. JWT-only doctests are wrapped in cfg(feature = "jwt") blocks so the feature matrix (cose-only / jwt-only / default) all pass cargo test cleanly. Signed-off-by: Kun Lai <laikun@linux.alibaba.com> Assisted-by: Claude <noreply@anthropic.com> Signed-off-by: Kun Lai <laikun@linux.alibaba.com>
Xynnn007
approved these changes
Jul 14, 2026
Contributor
Author
|
I accidentally deleted the branch which closed the PR, but it is now restored with the same commit ac0635f. Could you please take another look at #57? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Split COSE and JWT into two independent, default-on cargo features, and stop
cosefrom implyingjwt. Previously the three dependencies (cose-rust,openssl,jsonwebtoken) were unconditional, andcoseimpliedjwt— so JWT-only builds could not dropcose-rust+openssl, and the two features were not orthogonal.Motivation
EAR tokens can be serialized as either JWT or COSE, and the two are independent at the protocol level. In the original implementation, however:
cose-rust/openssl/jsonwebtokenwere all unconditional dependencies;cosefeature implied thejwtfeature — becausefrom_cose_jwkreuses thejsonwebtokencrate'sjwkmodule to parse the JWK verification key.That was a convenience reuse, not a fundamental requirement of COSE. For downstreams that only need JWT (or only COSE), this is unnecessary weight — especially since
openssl-sysdrags in a full native build.Changes
Cargo.tomlcose-rust/openssl/jsonwebtokenmarkedoptional = true.cosenow depends ondep:jsonwebtoken(the crate) rather than thejwtfeature.from_cose_jwkstill usesjsonwebtokento parse JWK, but does not pull in the jwt feature's API surface.src/ear.rs#[cfg(feature = ...)]to all COSE/JWT items:from_cose_jwk,from_cose,sign_cose_*,new_cose_header,alg_to_cose, and the COSE tests are gated oncose;from_jwt*,sign_jwt_*,new_jwt_header,alg_to_jwt_alg, and the JWT tests onjwt.use jsonwebtoken::{self as jwt, jwk};is guarded with#[cfg(any(feature = "cose", feature = "jwt"))]so the COSE path can access these shared types without forcing the jwt feature on. No runtime logic was changed.src/lib.rsnew_cose_header/new_jwt_headerre-exports are feature-gated.# #[cfg(feature = "jwt")] { ... # }so the full feature matrix passescargo test; the pre-existing shared example is marked```ignore (requires the cose and jwt features).Backward compatibility
default = ["cose", "jwt"]is unchanged, so out-of-the-box behavior is identical.--no-default-featuresnow selectcose/jwtas needed.Verification
cargo buildcargo test(lib)--no-default-features --features cose--no-default-features --features jwtcargo tree --no-default-features --features coseconfirms the cose-only build pullsjsonwebtokenas a direct dependency without compiling the jwt feature's code; the jwt-only build does not pullcose-rust/openssl.