Skip to content

Commit

Permalink
style: cargo clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ilbertt committed Apr 12, 2024
1 parent d7d17a1 commit 04edd68
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
6 changes: 2 additions & 4 deletions src/ic_backend/src/id_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ pub fn decode(token: &str, expected_alg: Algorithm) -> IdTokenResult<IdToken> {
return Err(ErrorKind::InvalidSignature);
}

let decoded_claims =
String::from_utf8(base64_decode(claims.as_ref())?).map_err(|e| ErrorKind::Utf8(e))?;
let claims: JWTClaims =
serde_json::from_str(&decoded_claims).map_err(|e| ErrorKind::Json(e))?;
let decoded_claims = String::from_utf8(base64_decode(claims)?).map_err(ErrorKind::Utf8)?;
let claims: JWTClaims = serde_json::from_str(&decoded_claims).map_err(ErrorKind::Json)?;

Ok(IdToken { header, claims })
}
12 changes: 2 additions & 10 deletions src/ic_backend/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,12 @@ pub const EMPTY_SALT: Salt = [0; 32];
// fetch JWKS every 1 hour
const JWKS_FETCH_INTERVAL: Duration = Duration::from_secs(60 * 60);

#[derive(Default)]
pub struct State {
pub sigs: SignatureMap,
pub jwks: Option<Auth0JWKSet>,
}

impl Default for State {
fn default() -> Self {
Self {
sigs: SignatureMap::default(),
jwks: None,
}
}
}

pub async fn init() {
ensure_salt_initialized().await;

Expand Down Expand Up @@ -92,7 +84,7 @@ pub async fn fetch_and_store_jwks() -> Result<(), String> {
serde_json::from_slice(&res.body).map_err(|e| format!("Error parsing JWKS: {:?}", e))?;
store_jwks(jwks.clone());

print(&format!(
print(format!(
"Fetched JWKS. JSON Web Keys available: {}",
jwks.keys.len()
));
Expand Down
2 changes: 1 addition & 1 deletion src/ic_backend/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn unix_timestamp() -> u64 {

pub fn base64_decode(input: &str) -> IdTokenResult<Vec<u8>> {
let engine = general_purpose::URL_SAFE_NO_PAD;
engine.decode(input).map_err(|e| ErrorKind::Base64(e))
engine.decode(input).map_err(ErrorKind::Base64)
}

pub fn principal_to_blob(principal: Principal) -> Blob<29> {
Expand Down
2 changes: 1 addition & 1 deletion src/ic_backend/tests/common/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn upgrade_canister(env: &TestEnv) {
}

fn load_canister_wasm_from_path(path: &PathBuf) -> Vec<u8> {
let mut file = File::open(&path)
let mut file = File::open(path)
.unwrap_or_else(|_| panic!("Failed to open file: {}", path.to_str().unwrap()));
let mut bytes = Vec::new();
file.read_to_end(&mut bytes).expect("Failed to read file");
Expand Down

0 comments on commit 04edd68

Please sign in to comment.