@@ -12,6 +12,7 @@ use x509_certificate::SignatureAlgorithm;
1212use x509_certificate:: certificate:: CapturedX509Certificate ;
1313
1414use crate :: api:: ClientInfo ;
15+ /// Re-exports client-side SCRAM authentication types.
1516#[ cfg( feature = "client-api" ) ]
1617pub use crate :: api:: auth:: sasl:: scram:: client:: * ;
1718use crate :: api:: auth:: { AuthSource , LoginInfo , Password } ;
@@ -25,15 +26,18 @@ use aws_lc_rs::{digest, hmac, pbkdf2};
2526#[ cfg( all( feature = "_ring" , not( feature = "_aws-lc-rs" ) ) ) ]
2627use ring:: { digest, hmac, pbkdf2} ;
2728
29+ /// Default SCRAM iteration count.
2830pub const SCRAM_ITERATIONS : usize = 4096 ;
2931
32+ /// SCRAM authentication configuration and state.
3033#[ derive( Debug ) ]
3134pub struct ScramAuth {
3235 auth_db : Arc < dyn AuthSource > ,
3336 authenticator : ScramServerAuth ,
3437}
3538
3639impl ScramAuth {
40+ /// Creates a new SCRAM auth instance.
3741 pub fn new ( auth_db : Arc < dyn AuthSource > ) -> ScramAuth {
3842 ScramAuth {
3943 auth_db,
@@ -62,6 +66,7 @@ impl ScramAuth {
6266 self . authenticator . set_iterations ( iterations) ;
6367 }
6468
69+ /// Returns `true` if channel binding is configured.
6570 pub fn supports_channel_binding ( & self ) -> bool {
6671 self . authenticator . server_cert_sig . is_some ( )
6772 }
@@ -84,6 +89,7 @@ pub fn gen_salted_password(password: &str, salt: &[u8], iters: usize) -> Vec<u8>
8489 hi ( pass_bytes, salt, iters)
8590}
8691
92+ /// Generates a random nonce for SCRAM authentication.
8793pub fn random_nonce ( ) -> String {
8894 STANDARD . encode ( rand:: random :: < [ u8 ; 18 ] > ( ) )
8995}
@@ -149,6 +155,7 @@ impl Default for ScramServerAuth {
149155}
150156
151157impl ScramServerAuth {
158+ /// Creates a new SCRAM server authenticator.
152159 pub fn new ( ) -> Self {
153160 Self {
154161 server_cert_sig : None ,
@@ -227,6 +234,7 @@ pub struct ScramServerAuthWaitingForClientFinal {
227234}
228235
229236impl ScramServerAuthWaitingForClientFinal {
237+ /// Processes the client final message and verifies the proof.
230238 pub fn on_client_final_message ( & self , client_final_message : & [ u8 ] ) -> PgWireResult < String > {
231239 let client_final = ClientFinal :: from_str ( decode_str ( client_final_message) ?) ?;
232240
@@ -267,12 +275,14 @@ mod client {
267275 use super :: * ;
268276 use crate :: error:: { PgWireClientError , PgWireClientResult } ;
269277
278+ /// Client-side SCRAM authenticator.
270279 pub struct ScramClientAuth {
271280 username : String ,
272281 password : String ,
273282 }
274283
275284 impl ScramClientAuth {
285+ /// Creates a new SCRAM client authenticator.
276286 pub fn new ( username : String , password : String ) -> Self {
277287 Self { username, password }
278288 }
0 commit comments