1
0
Fork 0
mirror of https://codeberg.org/tyy/aspm synced 2024-12-22 15:59:29 -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 {
fn from(value: reqwest::Error) -> Self {
if !value.is_status() {
return Self::Unknown(value);
Self::Unknown(value)
} else {
match value.status().unwrap() {
StatusCode::BAD_REQUEST => Self::BadRequest,
@ -52,7 +52,7 @@ pub enum AspeFetchFailure {
impl From<reqwest::Error> for AspeFetchFailure {
fn from(value: reqwest::Error) -> Self {
if !value.is_status() {
return Self::Unknown(value);
Self::Unknown(value)
} else {
match value.status().unwrap() {
StatusCode::NOT_FOUND => Self::NotFound,

View file

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

View file

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

View file

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

View file

@ -79,11 +79,8 @@ pub enum AspmSubcommands {
#[tokio::main]
async fn main() {
match cli().await {
Err(e) => {
eprintln!("An error occurred while running that command:\n{e}");
}
_ => (),
if let Err(e) = cli().await {
eprintln!("An error occurred while running that command:\n{e}");
}
}
@ -94,11 +91,11 @@ async fn cli() -> Result<(), anyhow::Error> {
let data_dir = parsed.data_dir.unwrap_or(
std::env::var("ASPM_DATA_DIR").map(|s| s.into()).unwrap_or(
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::read_dir(&data_dir).or(Err(AspmError::DataDirReadError))?;
std::fs::create_dir_all(&data_dir).or(Err(AspmError::DataDirCreate))?;
std::fs::read_dir(&data_dir).or(Err(AspmError::DataDirRead))?;
// Construct the database in the dir
let db = Database::connect(DATABASE_URL.replace("DB_PATH", &{
@ -136,9 +133,9 @@ async fn cli() -> Result<(), anyhow::Error> {
#[derive(Error, Debug)]
enum AspmError {
#[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?")]
DataDirReadError,
DataDirRead,
#[error("An unknown internal error occurred, please report this to the developer")]
UnknownError(#[source] anyhow::Error),
Unknown(#[source] anyhow::Error),
}