use scram_rs::ScramResult;
use scram_rs::ScramSha256;
use scram_rs::ScramAuthClient;
use scram_rs::ScramNonce;
use scram_rs::ClientChannelBindingType;
use scram_rs::scram_sync::SyncScramClient;
struct AuthClient
{
username: String,
password: String,
}
impl ScramAuthClient for AuthClient
{
fn get_username(&self) -> &String
{
return &self.username;
}
fn get_password(&self) -> &String
{
return &self.password;
}
}
impl AuthClient
{
pub fn new(u: &'static str, p: &'static str) -> Self
{
return AuthClient{username: u.to_string(), password: p.to_string()};
}
}
fn mock_stream_recv() -> String
{
return String::from("answer");
}
pub fn main() -> ScramResult<()>
{
let cbt = ClientChannelBindingType::without_chan_binding();
let ac = AuthClient::new("test", "testtest");
let nonce = ScramNonce::none();
let mut scram_res =
SyncScramClient::<ScramSha256, AuthClient>::new(&ac, nonce, cbt)?;
let _initial_msg = scram_res.init_client(true);
let answer = mock_stream_recv();
let res = scram_res.parse_response_base64(answer)?;
let _msg = res.extract_output()?;
let answer = mock_stream_recv();
let res = scram_res.parse_response_base64(answer)?;
if res.is_final() == false
{
panic!("error! in library SCRAM-RS");
}
return Ok(());
}