Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 520357e

Browse files
jplattesandhose
authored andcommitted
jose: Reduce stack size of JsonWebSignatureHeader
… by putting the optional jwk field behind a box. The overall size will be one pointer larger when the field is Some(_), but more than 300 bytes small when it is None.
1 parent 464eeda commit 520357e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

crates/jose/src/jwt/header.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct JsonWebSignatureHeader {
2828
jku: Option<Url>,
2929

3030
#[serde(default)]
31-
jwk: Option<PublicJsonWebKey>,
31+
jwk: Option<Box<PublicJsonWebKey>>,
3232

3333
#[serde(default)]
3434
kid: Option<String>,
@@ -91,12 +91,16 @@ impl JsonWebSignatureHeader {
9191

9292
#[must_use]
9393
pub const fn jwk(&self) -> Option<&PublicJsonWebKey> {
94-
self.jwk.as_ref()
94+
// Can't use as_deref because it's not a const fn
95+
match &self.jwk {
96+
Some(jwk) => Some(jwk),
97+
None => None,
98+
}
9599
}
96100

97101
#[must_use]
98102
pub fn with_jwk(mut self, jwk: PublicJsonWebKey) -> Self {
99-
self.jwk = Some(jwk);
103+
self.jwk = Some(Box::new(jwk));
100104
self
101105
}
102106

0 commit comments

Comments
 (0)