pub struct ScramClient {
pub client_nonce_b64: String,
pub client_first_bare: String,
pub client_first: String,
}Expand description
SCRAM-SHA-256 client state.
Holds the client nonce and first message needed for the authentication exchange.
Fields§
§client_nonce_b64: StringBase64-encoded client nonce (18 random bytes)
client_first_bare: StringClient-first-message-bare (without channel binding prefix)
client_first: StringComplete client-first-message to send to server
Implementations§
Source§impl ScramClient
impl ScramClient
Sourcepub fn new(username: &str) -> ScramClient
pub fn new(username: &str) -> ScramClient
Create a new SCRAM client with a random nonce.
§Arguments
username- PostgreSQL username (will be SASL-escaped)
Sourcepub fn parse_server_first(server_first: &str) -> Result<(String, String, u32)>
pub fn parse_server_first(server_first: &str) -> Result<(String, String, u32)>
Parse server-first-message.
Extracts:
r: Combined nonce (client nonce + server nonce)s: Base64-encoded salti: Iteration count
§Errors
Returns error if any required field is missing or malformed.
Sourcepub fn client_final(
&self,
password: &str,
server_first: &str,
) -> Result<(String, String, Vec<u8>)>
pub fn client_final( &self, password: &str, server_first: &str, ) -> Result<(String, String, Vec<u8>)>
Compute client-final-message.
§Arguments
password- User’s passwordserver_first- Server-first-message received from server
§Returns
Tuple of:
client_final: Message to send to serverauth_message: Full auth message (needed for server verification)salted_password: Derived key (needed for server verification)
§Errors
- Nonce doesn’t start with client nonce (possible MITM)
- Invalid base64 in salt
Sourcepub fn verify_server_final(
server_final: &str,
salted_password: &[u8],
auth_message: &str,
) -> Result<()>
pub fn verify_server_final( server_final: &str, salted_password: &[u8], auth_message: &str, ) -> Result<()>
Verify server-final-message.
This provides mutual authentication - ensures we’re talking to a server that knows the password, not an impostor.
§Arguments
server_final- Server-final-message receivedsalted_password- Fromclient_final()return valueauth_message- Fromclient_final()return value
§Errors
- Missing server signature
- Invalid base64
- Signature mismatch (server doesn’t know password)
Trait Implementations§
Source§impl Clone for ScramClient
impl Clone for ScramClient
Source§fn clone(&self) -> ScramClient
fn clone(&self) -> ScramClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ScramClient
impl RefUnwindSafe for ScramClient
impl Send for ScramClient
impl Sync for ScramClient
impl Unpin for ScramClient
impl UnwindSafe for ScramClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more