jsonwebtoken icon indicating copy to clipboard operation
jsonwebtoken copied to clipboard

Derive Default for JwkSet

Open tristan957 opened this issue 10 months ago • 4 comments

Useful for creating empty an empty JWKS.

tristan957 avatar Feb 10 '25 18:02 tristan957

What would be the use case for this change?

rimutaka avatar Feb 10 '25 18:02 rimutaka

What would be the use case for this change?

I want to send an empty JwkSet for whatever reason.

- let empty_set = JwkSet {
-   keys: Vec::default(),
- };
+ let empty_set = JwkSet::default();

tristan957 avatar Feb 10 '25 20:02 tristan957

@tristan957 , I feel like this change is setting someone for failure down the track. An empty JwkSet is a source of potential bugs - the compiler will not be able to reason because the struct is there, but the keys are not.

Making this explicit during the construction of the set feels safer to me.

rimutaka avatar Feb 10 '25 21:02 rimutaka

@tristan957 , I feel like this change is setting someone for failure down the track. An empty JwkSet is a source of potential bugs - the compiler will not be able to reason because the struct is there, but the keys are not.

Making this explicit during the construction of the set feels safer to me.

I'm not sure how someone could be set up for failure. I am requesting an empty JwkSet explicitly. What are the potential bugs here? How is this any different than the example I posted 1 comment ago?

tristan957 avatar Feb 10 '25 21:02 tristan957

I agree with @rimutaka I'd rather keep Default for things that are valid. The field is exposed so you can do what you want

Keats avatar Sep 29 '25 09:09 Keats