pub fn finish(&mut self, message: &[u8]) -> io::Result<()> {
        let (salted_password, auth_message) = match mem::replace(&mut self.state, State::Done) {
            State::Finish {
                salted_password,
                auth_message,
            } => (salted_password, auth_message),
            _ => return Err(io::Error::new(io::ErrorKind::Other, "invalid SCRAM state")),
        };

        let message = str::from_utf8(message).map_err(|e| {
            io::Error::new(io::ErrorKind::InvalidInput, e)
        })?;

        let parsed = Parser::new(message).server_final_message()?;

        let verifier = match parsed {
            ServerFinalMessage::Error(e) => {
                return Err(io::Error::new(
                    io::ErrorKind::Other,
                    format!("SCRAM error: {}", e),
                ))
            }
            ServerFinalMessage::Verifier(verifier) => verifier,
        };

        let verifier = match base64::decode(verifier) {
            Ok(verifier) => verifier,
            Err(e) => return Err(io::Error::new(io::ErrorKind::InvalidInput, e)),
        };

        let mut hmac = Hmac::<Sha256>::new(&salted_password)
            .expect("HMAC is able to accept all key sizes");
        hmac.input(b"Server Key");
        let server_key = hmac.result();

        let mut hmac = Hmac::<Sha256>::new(&server_key.code())
            .expect("HMAC is able to accept all key sizes");
        hmac.input(auth_message.as_bytes());
        hmac.verify(&verifier).map_err(|_| io::Error::new(
            io::ErrorKind::InvalidInput,
            "SCRAM verification error",
        ))
    }
/// Finalizes the authentication process.
///
/// This should be called when the backend sends an `AuthenticationSASLFinal` message.
/// Authentication has only succeeded if this method returns `Ok(())`.
Finalizes the authentication process.
This should be called when the backend sends an `AuthenticationSASLFinal` message.
Authentication has only succeeded if this method returns `Ok(())`.
Finalizes the authentication process . This should be called when the backend sends an ` AuthenticationSASLFinal ` message . Authentication has only succeeded if this method returns ` Ok (( )) ` .
pub fn finish(&mut self, message: &[u8]) -> io::Result<()> {
        let (salted_password, auth_message) = match mem::replace(&mut self.state, State::Done) {
            State::Finish {
                salted_password,
                auth_message,
            } => (salted_password, auth_message),
            _ => return Err(io::Error::new(io::ErrorKind::Other, "invalid SCRAM state")),
        };
        let message = str::from_utf8(message).map_err(|e| {
            io::Error::new(io::ErrorKind::InvalidInput, e)
        })?;
        let parsed = Parser::new(message).server_final_message()?;
        let verifier = match parsed {
            ServerFinalMessage::Error(e) => {
                return Err(io::Error::new(
                    io::ErrorKind::Other,
                    format!("SCRAM error: {}", e),
                ))
            }
            ServerFinalMessage::Verifier(verifier) => verifier,
        };
        let verifier = match base64::decode(verifier) {
            Ok(verifier) => verifier,
            Err(e) => return Err(io::Error::new(io::ErrorKind::InvalidInput, e)),
        };
        let mut hmac = Hmac::<Sha256>::new(&salted_password)
            .expect("HMAC is able to accept all key sizes");
        hmac.input(b"Server Key");
        let server_key = hmac.result();
        let mut hmac = Hmac::<Sha256>::new(&server_key.code())
            .expect("HMAC is able to accept all key sizes");
        hmac.input(auth_message.as_bytes());
        hmac.verify(&verifier).map_err(|_| io::Error::new(
            io::ErrorKind::InvalidInput,
            "SCRAM verification error",
        ))
    }
pub fn finish ( & mut self , message : & [ u8 ] ) -> io :: Result < ( ) > { let ( salted_password , auth_message ) = match mem :: replace ( & mut self . state , State :: Done ) { State :: Finish { salted_password , auth_message , } => ( salted_password , auth_message ) , _ => return Err ( io :: Error :: new ( io :: ErrorKind :: Other , " " ) ) , } ; let message = str :: from_utf8 ( message ) . map_err ( | e | { io :: Error :: new ( io :: ErrorKind :: InvalidInput , e ) } ) ? ; let parsed = Parser :: new ( message ) . server_final_message ( ) ? ; let verifier = match parsed { ServerFinalMessage :: Error ( e ) => { return Err ( io :: Error :: new ( io :: ErrorKind :: Other , format ! ( " " e ) , ) ) } ServerFinalMessage :: Verifier ( verifier ) => verifier , } ; let verifier = match base64 :: decode ( verifier ) { Ok ( verifier ) => verifier , Err ( e ) => return Err ( io :: Error :: new ( io :: ErrorKind :: InvalidInput , e ) ) , } ; let mut hmac = Hmac :: < Sha256 > :: new ( & salted_password ) . expect ( " " ) ; hmac . input ( b" " ) ; let server_key = hmac . result ( ) ; let mut hmac = Hmac :: < Sha256 > :: new ( & server_key . code ( ) ) . expect ( " " ) ; hmac . input ( auth_message . as_bytes ( ) ) ; hmac . verify ( & verifier ) . map_err ( | _ | io :: Error :: new ( io :: ErrorKind :: InvalidInput , " " , ) ) }
Finalizes the authentication process.
Finalizes the authentication process .
&mut self
message
&[u8]
&mut self
message
&[u8]