1
0
Fork 0
mirror of https://codeberg.org/tyy/aspm synced 2024-12-23 01:19:28 -07:00

Fix clippy warnings

This commit is contained in:
TymanWasTaken 2023-07-02 19:28:40 -04:00
parent 954d6fac2e
commit b44f4ca359
Signed by: Ty
GPG key ID: 2813440C772555A4
5 changed files with 19 additions and 22 deletions

View file

@ -26,7 +26,7 @@ pub enum AspeRequestFailure {
impl From<reqwest::Error> for AspeRequestFailure { impl From<reqwest::Error> for AspeRequestFailure {
fn from(value: reqwest::Error) -> Self { fn from(value: reqwest::Error) -> Self {
if !value.is_status() { if !value.is_status() {
return Self::Unknown(value); Self::Unknown(value)
} else { } else {
match value.status().unwrap() { match value.status().unwrap() {
StatusCode::BAD_REQUEST => Self::BadRequest, StatusCode::BAD_REQUEST => Self::BadRequest,
@ -52,7 +52,7 @@ pub enum AspeFetchFailure {
impl From<reqwest::Error> for AspeFetchFailure { impl From<reqwest::Error> for AspeFetchFailure {
fn from(value: reqwest::Error) -> Self { fn from(value: reqwest::Error) -> Self {
if !value.is_status() { if !value.is_status() {
return Self::Unknown(value); Self::Unknown(value)
} else { } else {
match value.status().unwrap() { match value.status().unwrap() {
StatusCode::NOT_FOUND => Self::NotFound, StatusCode::NOT_FOUND => Self::NotFound,

View file

@ -20,11 +20,11 @@ pub enum AspKeyType {
ES256, ES256,
} }
impl Into<i32> for AspKeyType { impl From<AspKeyType> for i32 {
fn into(self) -> i32 { fn from(value: AspKeyType) -> Self {
match self { match value {
Self::Ed25519 => 0, AspKeyType::Ed25519 => 0,
Self::ES256 => 1, AspKeyType::ES256 => 1,
} }
} }
} }

View file

@ -92,7 +92,7 @@ impl JwtExt for Jwk {
fn from_encrypted(secret: &[u8], jwe: &str) -> anyhow::Result<Jwk> { fn from_encrypted(secret: &[u8], jwe: &str) -> anyhow::Result<Jwk> {
let decrypter = A256gcmkw.decrypter_from_bytes(secret)?; let decrypter = A256gcmkw.decrypter_from_bytes(secret)?;
let (deserialized, _) = jwe::deserialize_compact(jwe, &decrypter)?; let (deserialized, _) = jwe::deserialize_compact(jwe, &decrypter)?;
let jwk = Jwk::from_bytes(&deserialized)?; let jwk = Jwk::from_bytes(deserialized)?;
Ok(jwk) Ok(jwk)
} }

View file

@ -52,7 +52,7 @@ impl<O: JwtSerializable + Serialize + for<'de> Deserialize<'de>> JwtSerialize fo
let mut header = JwsHeader::new(); let mut header = JwsHeader::new();
header.set_token_type("JWT"); header.set_token_type("JWT");
header header
.set_asp_key(&key) .set_asp_key(key)
.or(Err(JwtSerializationError::JwkUsageError))?; .or(Err(JwtSerializationError::JwkUsageError))?;
// Construct the payload // Construct the payload
@ -66,14 +66,14 @@ impl<O: JwtSerializable + Serialize + for<'de> Deserialize<'de>> JwtSerialize fo
.or(Err(JwtSerializationError::PayloadSerializationError))?; .or(Err(JwtSerializationError::PayloadSerializationError))?;
// Sign it into a JWT // Sign it into a JWT
Ok(jwt::encode_with_signer( jwt::encode_with_signer(
&payload, &payload,
&header, &header,
&*key &*key
.create_signer() .create_signer()
.or(Err(JwtSerializationError::JwkUsageError))?, .or(Err(JwtSerializationError::JwkUsageError))?,
) )
.or(Err(JwtSerializationError::SerializationError))?) .or(Err(JwtSerializationError::SerializationError))
} }
fn decode_and_verify(jwt: &str, key: &AspKey) -> Result<Box<Self>, JwtDeserializationError> fn decode_and_verify(jwt: &str, key: &AspKey) -> Result<Box<Self>, JwtDeserializationError>

View file

@ -79,12 +79,9 @@ pub enum AspmSubcommands {
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
match cli().await { if let Err(e) = cli().await {
Err(e) => {
eprintln!("An error occurred while running that command:\n{e}"); eprintln!("An error occurred while running that command:\n{e}");
} }
_ => (),
}
} }
async fn cli() -> Result<(), anyhow::Error> { async fn cli() -> Result<(), anyhow::Error> {
@ -94,11 +91,11 @@ async fn cli() -> Result<(), anyhow::Error> {
let data_dir = parsed.data_dir.unwrap_or( let data_dir = parsed.data_dir.unwrap_or(
std::env::var("ASPM_DATA_DIR").map(|s| s.into()).unwrap_or( std::env::var("ASPM_DATA_DIR").map(|s| s.into()).unwrap_or(
app_dirs2::get_app_root(AppDataType::UserData, &APP_INFO) app_dirs2::get_app_root(AppDataType::UserData, &APP_INFO)
.map_err(|e| AspmError::UnknownError(e.into()))?, .map_err(|e| AspmError::Unknown(e.into()))?,
), ),
); );
std::fs::create_dir_all(&data_dir).or(Err(AspmError::DataDirCreateError))?; std::fs::create_dir_all(&data_dir).or(Err(AspmError::DataDirCreate))?;
std::fs::read_dir(&data_dir).or(Err(AspmError::DataDirReadError))?; std::fs::read_dir(&data_dir).or(Err(AspmError::DataDirRead))?;
// Construct the database in the dir // Construct the database in the dir
let db = Database::connect(DATABASE_URL.replace("DB_PATH", &{ let db = Database::connect(DATABASE_URL.replace("DB_PATH", &{
@ -136,9 +133,9 @@ async fn cli() -> Result<(), anyhow::Error> {
#[derive(Error, Debug)] #[derive(Error, Debug)]
enum AspmError { enum AspmError {
#[error("The data directory was unable to be created, is it correct, and does the current user have permission to create it?")] #[error("The data directory was unable to be created, is it correct, and does the current user have permission to create it?")]
DataDirCreateError, DataDirCreate,
#[error("The data directory was unable to be read, is it correct, and does the current user have permission to read it?")] #[error("The data directory was unable to be read, is it correct, and does the current user have permission to read it?")]
DataDirReadError, DataDirRead,
#[error("An unknown internal error occurred, please report this to the developer")] #[error("An unknown internal error occurred, please report this to the developer")]
UnknownError(#[source] anyhow::Error), Unknown(#[source] anyhow::Error),
} }