fn validate_login_cookie(
    settings: Arc<Settings>,
    headers: &HeaderMap,
) -> Option<(String, String, String)> {
    let login_cookie = headers
        .typed_get::<headers::Cookie>()
        .and_then(|cookie| cookie.get(&settings.login_cookie).map(str::to_string))?;
    let mut parts = login_cookie.split('.');
    let payload = base64::decode_config(parts.next()?, base64::URL_SAFE_NO_PAD).ok()?;
    let signature = base64::decode_config(parts.next()?, base64::URL_SAFE_NO_PAD).ok()?;
    let hmac = hmac_sha256::HMAC::mac(&payload, settings.cookie_secret.as_bytes());

    // There is no need to be subtle here, all the information is already exposed
    if &hmac[..] != signature.as_slice() {
        return None;
    }
    let mut payload_parts = payload.split(|b| *b == 0u8);
    let state = String::from_utf8(payload_parts.next()?.to_vec()).ok()?;
    let redirect_url = String::from_utf8(payload_parts.next()?.to_vec()).ok()?;
    let origin = String::from_utf8(payload_parts.next()?.to_vec()).ok()?;

    Some((state, redirect_url, origin))
}
// Validate the contents of the temporary cookie used during the login flow
// (i.e. that is constructed in login_redirect and consumed in oauth_callback)
Validate the contents of the temporary cookie used during the login flow
Validate the contents of the temporary cookie used during the login flow
fn validate_login_cookie(
    settings: Arc<Settings>,
    headers: &HeaderMap,
) -> Option<(String, String, String)> {
    let login_cookie = headers
        .typed_get::<headers::Cookie>()
        .and_then(|cookie| cookie.get(&settings.login_cookie).map(str::to_string))?;
    let mut parts = login_cookie.split('.');
    let payload = base64::decode_config(parts.next()?, base64::URL_SAFE_NO_PAD).ok()?;
    let signature = base64::decode_config(parts.next()?, base64::URL_SAFE_NO_PAD).ok()?;
    let hmac = hmac_sha256::HMAC::mac(&payload, settings.cookie_secret.as_bytes());
    // There is no need to be subtle here, all the information is already exposed
    if &hmac[..] != signature.as_slice() {
        return None;
    }
    let mut payload_parts = payload.split(|b| *b == 0u8);
    let state = String::from_utf8(payload_parts.next()?.to_vec()).ok()?;
    let redirect_url = String::from_utf8(payload_parts.next()?.to_vec()).ok()?;
    let origin = String::from_utf8(payload_parts.next()?.to_vec()).ok()?;
    Some((state, redirect_url, origin))
}
fn validate_login_cookie ( settings : Arc < Settings > , headers : & HeaderMap , ) -> Option < ( String , String , String ) > { let login_cookie = headers . typed_get :: < headers :: Cookie > ( ) . and_then ( | cookie | cookie . get ( & settings . login_cookie ) . map ( str :: to_string ) ) ? ; let mut parts = login_cookie . split ( '.' ) ; let payload = base64 :: decode_config ( parts . next ( ) ? , base64 :: URL_SAFE_NO_PAD ) . ok ( ) ? ; let signature = base64 :: decode_config ( parts . next ( ) ? , base64 :: URL_SAFE_NO_PAD ) . ok ( ) ? ; let hmac = hmac_sha256 :: HMAC :: mac ( & payload , settings . cookie_secret . as_bytes ( ) ) ; // There is no need to be subtle here, all the information is already exposed if & hmac [ .. ] != signature . as_slice ( ) { return None ; } let mut payload_parts = payload . split ( | b | * b == 0u8 ) ; let state = String :: from_utf8 ( payload_parts . next ( ) ? . to_vec ( ) ) . ok ( ) ? ; let redirect_url = String :: from_utf8 ( payload_parts . next ( ) ? . to_vec ( ) ) . ok ( ) ? ; let origin = String :: from_utf8 ( payload_parts . next ( ) ? . to_vec ( ) ) . ok ( ) ? ; Some ( ( state , redirect_url , origin ) ) }
Validate the contents of the temporary cookie used during the login flow
(i.e.
Validate the contents of the temporary cookie used during the login flow ( i . e .
settings
Arc<Settings>
headers
&HeaderMap
settings
Arc<Settings>
headers
&HeaderMap