Add ImportError to AuthenticationError enum

This commit is contained in:
silverpill 2022-11-27 10:53:51 +00:00
parent 7511832fa0
commit 8dfd8bf0d7

View file

@ -48,7 +48,10 @@ pub enum AuthenticationError {
DatabaseError(#[from] DatabaseError), DatabaseError(#[from] DatabaseError),
#[error("{0}")] #[error("{0}")]
ActorError(String), ImportError(String),
#[error("{0}")]
ActorError(&'static str),
#[error("invalid public key")] #[error("invalid public key")]
InvalidPublicKey(#[from] rsa::pkcs8::Error), InvalidPublicKey(#[from] rsa::pkcs8::Error),
@ -92,12 +95,12 @@ pub async fn verify_signed_request(
Ok(profile) => profile, Ok(profile) => profile,
Err(HandlerError::DatabaseError(error)) => return Err(error.into()), Err(HandlerError::DatabaseError(error)) => return Err(error.into()),
Err(other_error) => { Err(other_error) => {
return Err(AuthenticationError::ActorError(other_error.to_string())); return Err(AuthenticationError::ImportError(other_error.to_string()));
}, },
} }
}; };
let actor = actor_profile.actor_json.as_ref() let actor = actor_profile.actor_json.as_ref()
.ok_or(AuthenticationError::ActorError("invalid profile".to_string()))?; .ok_or(AuthenticationError::ActorError("local signer"))?;
let public_key = deserialize_public_key(&actor.public_key.public_key_pem)?; let public_key = deserialize_public_key(&actor.public_key.public_key_pem)?;
verify_http_signature(&signature_data, &public_key)?; verify_http_signature(&signature_data, &public_key)?;
@ -134,11 +137,11 @@ pub async fn verify_signed_activity(
return Err(error.into()); return Err(error.into());
}, },
Err(other_error) => { Err(other_error) => {
return Err(AuthenticationError::ActorError(other_error.to_string())); return Err(AuthenticationError::ImportError(other_error.to_string()));
}, },
}; };
let actor = actor_profile.actor_json.as_ref() let actor = actor_profile.actor_json.as_ref()
.ok_or(AuthenticationError::ActorError("invalid profile".to_string()))?; .ok_or(AuthenticationError::ActorError("local signer"))?;
let public_key = let public_key =
deserialize_public_key(&actor.public_key.public_key_pem)?; deserialize_public_key(&actor.public_key.public_key_pem)?;
verify_rsa_json_signature(&signature_data, &public_key)?; verify_rsa_json_signature(&signature_data, &public_key)?;
@ -184,7 +187,7 @@ pub async fn verify_signed_activity(
}; };
profile profile
} else { } else {
return Err(AuthenticationError::ActorError("unknown signer".to_string())); return Err(AuthenticationError::ActorError("unknown signer"));
} }
}, },
}; };