Skip to content

Commit b786c5c

Browse files
committed
fixup: use the unit type to return an error from jwt setup
there is only one possible error here so keep things simple for now
1 parent 582a3d5 commit b786c5c

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

rust/auth-impls/src/jwt.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,22 @@ pub(crate) struct Claims {
3636

3737
const BEARER_PREFIX: &str = "Bearer ";
3838

39-
fn parse_public_key_pem(pem: &str) -> Result<PKey<Public>, String> {
39+
fn parse_public_key_pem(pem: &str) -> Result<PKey<Public>, ()> {
4040
let body = pem
4141
.trim()
4242
.strip_prefix("-----BEGIN PUBLIC KEY-----")
43-
.ok_or(String::from("Prefix not found"))?
43+
.ok_or(())?
4444
.strip_suffix("-----END PUBLIC KEY-----")
45-
.ok_or(String::from("Suffix not found"))?;
45+
.ok_or(())?;
4646
let body: String = body.lines().map(|line| line.trim()).collect();
47-
let body = STANDARD.decode(body).map_err(|_| String::from("Base64 decode failed"))?;
48-
PKey::public_key_from_der(&body).map_err(|_| String::from("DER decode failed"))
47+
let body = STANDARD.decode(body).map_err(|_| ())?;
48+
PKey::public_key_from_der(&body).map_err(|_| ())
4949
}
5050

5151
impl JWTAuthorizer {
5252
/// Creates a new instance of [`JWTAuthorizer`], fails on failure to parse the PEM formatted RSA public key
53-
pub async fn new(rsa_pem: &str) -> Result<Self, String> {
54-
let jwt_issuer_key = parse_public_key_pem(rsa_pem)
55-
.map_err(|e| format!("Failed to parse the PEM formatted RSA public key: {}", e))?;
53+
pub async fn new(rsa_pem: &str) -> Result<Self, ()> {
54+
let jwt_issuer_key = parse_public_key_pem(rsa_pem)?;
5655
Ok(Self { jwt_issuer_key })
5756
}
5857
}

rust/server/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ fn main() {
8686
info!("Configured JWT authorizer with RSA public key");
8787
Some(Arc::new(auth))
8888
},
89-
Err(e) => {
90-
error!("Failed to configure JWT authorizer: {}", e);
89+
Err(()) => {
90+
error!("Failed to configure JWT authorizer");
9191
std::process::exit(-1);
9292
},
9393
};

0 commit comments

Comments
 (0)