azure_jwt_async 0.3.2

A simple JWT validator for Microsoft Azure tokens that is async capable.
Documentation
use crate::jwt;
use std::{error::Error, fmt};

#[derive(Debug)]
pub enum AuthErr {
    InvalidToken(jwt::errors::Error),
    ConnectionError(reqwest::Error),
    Other(String),
    ParseError(String),
}

impl Error for AuthErr {}

impl fmt::Display for AuthErr {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        use AuthErr::*;

        match self {
            InvalidToken(err) => write!(f, "Invalid token. {}", err),
            ConnectionError(err) => write!(f, "Could not connect to Microsoft. {}", err),
            Other(msg) => write!(f, "An error occurred: {}", msg),
            ParseError(msg) => write!(f, "Could not parse token. {}", msg),
        }
    }
}

impl From<reqwest::Error> for AuthErr {
    fn from(e: reqwest::Error) -> AuthErr {
        AuthErr::ConnectionError(e)
    }
}

impl From<jwt::errors::Error> for AuthErr {
    fn from(e: jwt::errors::Error) -> AuthErr {
        AuthErr::InvalidToken(e)
    }
}