pub fn verify_token<T: AsRef<[u8]>>(
        &self,
        token: T,
        chap_hash: &str,
    ) -> Result<(), TokenError> {
        // extract nonce and cipher, then decypt
        let payload = {
            let (nonce, cipher) = Self::token_to_cipher(token.as_ref())?;
            self.decrypt_token(&nonce, cipher)?
        };

        // convert bytes to string, then deserialize into json
        let payload = std::str::from_utf8(&payload).ok().and_then(|s| {
            log::trace!("token payload: {}", s);
            json::from_str::<TokenPayload>(s).ok()
        });

        // verify contents inside the payload if the payload itself is valid
        if let Some(payload) = payload {
            // verify the chapter hash
            if payload.hash != chap_hash {
                return Err(TokenError::InvalidChapterHash);
            }
            // verify the token isn't expired
            let date = chrono::DateTime::parse_from_rfc3339(&payload.expires).map_err(|e| {
                log::error!("rfc3339 parse err: {}", e);
                TokenError::InvalidPayload
            })?;
            return if date > chrono::Local::now() {
                // token is not expired, so it's valid
                Ok(())
            } else {
                Err(TokenError::TokenExpired)
            };
        }
        // if deserialization failed, then there was an invalid payload
        Err(TokenError::InvalidPayload)
    }
/// Takes a string of bytes as a token, decrypts it using the stored PrecomputedKey, then
/// verifies that it matches the chapter hash and is not expired.
///
/// This method can result in a multitude of different errors, however it only results in
/// `Ok(())` if the result itself can be successfully decrypted, parsed, matches the chapter hash
/// and is not expired.
Takes a string of bytes as a token, decrypts it using the stored PrecomputedKey, then
verifies that it matches the chapter hash and is not expired.

This method can result in a multitude of different errors, however it only results in
`Ok(())` if the result itself can be successfully decrypted, parsed, matches the chapter hash
and is not expired.
Takes a string of bytes as a token decrypts it using the stored PrecomputedKey then verifies that it matches the chapter hash and is not expired . This method can result in a multitude of different errors however it only results in ` Ok (( )) ` if the result itself can be successfully decrypted parsed matches the chapter hash and is not expired .
pub fn verify_token<T: AsRef<[u8]>>(
        &self,
        token: T,
        chap_hash: &str,
    ) -> Result<(), TokenError> {
        // extract nonce and cipher, then decypt
        let payload = {
            let (nonce, cipher) = Self::token_to_cipher(token.as_ref())?;
            self.decrypt_token(&nonce, cipher)?
        };
        // convert bytes to string, then deserialize into json
        let payload = std::str::from_utf8(&payload).ok().and_then(|s| {
            log::trace!("token payload: {}", s);
            json::from_str::<TokenPayload>(s).ok()
        });
        // verify contents inside the payload if the payload itself is valid
        if let Some(payload) = payload {
            // verify the chapter hash
            if payload.hash != chap_hash {
                return Err(TokenError::InvalidChapterHash);
            }
            // verify the token isn't expired
            let date = chrono::DateTime::parse_from_rfc3339(&payload.expires).map_err(|e| {
                log::error!("rfc3339 parse err: {}", e);
                TokenError::InvalidPayload
            })?;
            return if date > chrono::Local::now() {
                // token is not expired, so it's valid
                Ok(())
            } else {
                Err(TokenError::TokenExpired)
            };
        }
        // if deserialization failed, then there was an invalid payload
        Err(TokenError::InvalidPayload)
    }
pub fn verify_token < T : AsRef < [ u8 ] > > ( & self , token : T , chap_hash : & str , ) -> Result < ( ) , TokenError > { // extract nonce and cipher, then decypt let payload = { let ( nonce , cipher ) = Self :: token_to_cipher ( token . as_ref ( ) ) ? ; self . decrypt_token ( & nonce , cipher ) ? } ; // convert bytes to string, then deserialize into json let payload = std :: str :: from_utf8 ( & payload ) . ok ( ) . and_then ( | s | { log :: trace ! ( " " s ) ; json :: from_str :: < TokenPayload > ( s ) . ok ( ) } ) ; // verify contents inside the payload if the payload itself is valid if let Some ( payload ) = payload { // verify the chapter hash if payload . hash != chap_hash { return Err ( TokenError :: InvalidChapterHash ) ; } // verify the token isn't expired let date = chrono :: DateTime :: parse_from_rfc3339 ( & payload . expires ) . map_err ( | e | { log :: error ! ( " " e ) ; TokenError :: InvalidPayload } ) ? ; return if date > chrono :: Local :: now ( ) { // token is not expired, so it's valid Ok ( ( ) ) } else { Err ( TokenError :: TokenExpired ) } ; } // if deserialization failed, then there was an invalid payload Err ( TokenError :: InvalidPayload ) }
Takes a string of bytes as a token, decrypts it using the stored PrecomputedKey, then
verifies that it matches the chapter hash and is not expired.
Takes a string of bytes as a token decrypts it using the stored PrecomputedKey then verifies that it matches the chapter hash and is not expired .
&self
token
T
chap_hash
&str