Skip to content

Commit 3accc5f

Browse files
authored
docs: add simple comments to pub items (#430)
1 parent 6d72c4a commit 3accc5f

43 files changed

Lines changed: 392 additions & 37 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/api/auth/cleartext.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::error::{PgWireError, PgWireResult};
1313
use crate::messages::startup::Authentication;
1414
use crate::messages::{PgWireBackendMessage, PgWireFrontendMessage};
1515

16+
/// Startup handler for cleartext password authentication.
1617
pub struct CleartextPasswordAuthStartupHandler<A, P> {
1718
auth_source: A,
1819
parameter_provider: P,
@@ -21,6 +22,7 @@ pub struct CleartextPasswordAuthStartupHandler<A, P> {
2122
}
2223

2324
impl<A, P> CleartextPasswordAuthStartupHandler<A, P> {
25+
/// Creates a new cleartext password auth handler.
2426
pub fn new(auth_source: A, parameter_provider: P) -> Self {
2527
Self {
2628
auth_source,
@@ -30,6 +32,7 @@ impl<A, P> CleartextPasswordAuthStartupHandler<A, P> {
3032
}
3133
}
3234

35+
/// Sets a custom PID/secret key generator.
3336
pub fn with_pid_secret_key_generator(
3437
mut self,
3538
generator: Arc<dyn PidSecretKeyGenerator>,
@@ -38,6 +41,7 @@ impl<A, P> CleartextPasswordAuthStartupHandler<A, P> {
3841
self
3942
}
4043

44+
/// Sets a connection manager.
4145
pub fn with_connection_manager(mut self, manager: Arc<ConnectionManager>) -> Self {
4246
self.connection_manager = Some(manager);
4347
self

src/api/auth/md5pass.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::error::{PgWireError, PgWireResult};
1414
use crate::messages::startup::Authentication;
1515
use crate::messages::{PgWireBackendMessage, PgWireFrontendMessage};
1616

17+
/// Startup handler for MD5 password authentication.
1718
pub struct Md5PasswordAuthStartupHandler<A, P> {
1819
auth_source: Arc<A>,
1920
parameter_provider: Arc<P>,
@@ -23,6 +24,7 @@ pub struct Md5PasswordAuthStartupHandler<A, P> {
2324
}
2425

2526
impl<A, P> Md5PasswordAuthStartupHandler<A, P> {
27+
/// Creates a new MD5 password auth handler.
2628
pub fn new(auth_source: Arc<A>, parameter_provider: Arc<P>) -> Self {
2729
Md5PasswordAuthStartupHandler {
2830
auth_source,
@@ -33,6 +35,7 @@ impl<A, P> Md5PasswordAuthStartupHandler<A, P> {
3335
}
3436
}
3537

38+
/// Sets a custom PID/secret key generator.
3639
pub fn with_pid_secret_key_generator(
3740
mut self,
3841
generator: Arc<dyn PidSecretKeyGenerator>,
@@ -41,6 +44,7 @@ impl<A, P> Md5PasswordAuthStartupHandler<A, P> {
4144
self
4245
}
4346

47+
/// Sets a connection manager.
4448
pub fn with_connection_manager(mut self, manager: Arc<ConnectionManager>) -> Self {
4549
self.connection_manager = Some(manager);
4650
self

src/api/auth/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub trait StartupHandler: Send + Sync {
3232
PgWireError: From<<C as Sink<PgWireBackendMessage>>::Error>;
3333
}
3434

35+
/// Provides server parameters to send to the client during startup.
3536
pub trait ServerParameterProvider: Send + Sync {
3637
fn server_parameters<C>(&self, _client: &C) -> Option<HashMap<String, String>>
3738
where
@@ -185,22 +186,26 @@ impl ServerParameterProvider for DefaultServerParameterProvider {
185186
}
186187
}
187188

189+
/// Represents a password with an optional salt.
188190
#[derive(Debug, new, Clone)]
189191
pub struct Password {
190192
salt: Option<Vec<u8>>,
191193
password: Vec<u8>,
192194
}
193195

194196
impl Password {
197+
/// Returns the salt, if any.
195198
pub fn salt(&self) -> Option<&[u8]> {
196199
self.salt.as_deref()
197200
}
198201

202+
/// Returns the password bytes.
199203
pub fn password(&self) -> &[u8] {
200204
&self.password
201205
}
202206
}
203207

208+
/// Login information extracted from the client connection.
204209
#[derive(Debug, new)]
205210
pub struct LoginInfo<'a> {
206211
user: Option<&'a str>,
@@ -209,18 +214,22 @@ pub struct LoginInfo<'a> {
209214
}
210215

211216
impl LoginInfo<'_> {
217+
/// Returns the user name.
212218
pub fn user(&self) -> Option<&str> {
213219
self.user
214220
}
215221

222+
/// Returns the database name.
216223
pub fn database(&self) -> Option<&str> {
217224
self.database
218225
}
219226

227+
/// Returns the client host address.
220228
pub fn host(&self) -> &str {
221229
&self.host
222230
}
223231

232+
/// Creates `LoginInfo` from a client.
224233
pub fn from_client_info<C>(client: &C) -> LoginInfo<'_>
225234
where
226235
C: ClientInfo,
@@ -248,6 +257,7 @@ pub trait AuthSource: Send + Sync + Debug {
248257
async fn get_password(&self, login: &LoginInfo) -> PgWireResult<Password>;
249258
}
250259

260+
/// Negotiates the protocol version with the client.
251261
pub async fn protocol_negotiation<C>(client: &mut C, startup_message: &Startup) -> PgWireResult<()>
252262
where
253263
C: ClientInfo + Sink<PgWireBackendMessage> + Unpin,
@@ -280,6 +290,7 @@ where
280290
}
281291
}
282292

293+
/// Saves startup message parameters into client metadata.
283294
pub fn save_startup_parameters_to_metadata<C>(client: &mut C, startup_message: &Startup)
284295
where
285296
C: ClientInfo,
@@ -338,6 +349,7 @@ where
338349
Ok(())
339350
}
340351

352+
/// Completes authentication by sending `AuthenticationOk`, parameter status, backend key data, and `ReadyForQuery`.
341353
pub async fn finish_authentication<C, P>(
342354
client: &mut C,
343355
server_parameter_provider: &P,

src/api/auth/noop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::messages::response::{ReadyForQuery, TransactionStatus};
1313
use crate::messages::{PgWireBackendMessage, PgWireFrontendMessage};
1414

1515
#[async_trait]
16+
/// A startup handler that performs no authentication.
1617
pub trait NoopStartupHandler: StartupHandler {
1718
fn connection_manager(&self) -> Option<Arc<ConnectionManager>> {
1819
None

src/api/auth/sasl.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ use super::{ServerParameterProvider, StartupHandler};
1919
pub mod oauth;
2020
pub mod scram;
2121

22+
/// SASL mechanism name for SCRAM-SHA-256.
2223
pub const SCRAM_SHA_256_METHOD: &str = "SCRAM-SHA-256";
24+
/// SASL mechanism name for SCRAM-SHA-256-PLUS with channel binding.
2325
pub const SCRAM_SHA_256_PLUS_METHOD: &str = "SCRAM-SHA-256-PLUS";
26+
/// SASL mechanism name for OAUTHBEARER.
2427
pub const OAUTHBEARER_METHOD: &str = "OAUTHBEARER";
2528

29+
/// States of the SASL authentication state machine.
2630
#[derive(Debug)]
2731
pub enum SASLState {
2832
Initial,
@@ -51,6 +55,7 @@ impl SASLState {
5155
}
5256
}
5357

58+
/// Startup handler for SASL-based authentication (SCRAM and OAUTHBEARER).
5459
pub struct SASLAuthStartupHandler<P> {
5560
parameter_provider: Arc<P>,
5661
pid_secret_key_generator: Arc<dyn PidSecretKeyGenerator>,
@@ -64,6 +69,7 @@ pub struct SASLAuthStartupHandler<P> {
6469
}
6570

6671
impl<P> SASLAuthStartupHandler<P> {
72+
/// Creates a new SASL auth handler.
6773
pub fn new(parameter_provider: Arc<P>) -> Self {
6874
SASLAuthStartupHandler {
6975
parameter_provider,
@@ -75,16 +81,19 @@ impl<P> SASLAuthStartupHandler<P> {
7581
}
7682
}
7783

84+
/// Configures SCRAM authentication.
7885
pub fn with_scram(mut self, scram_auth: scram::ScramAuth) -> Self {
7986
self.scram = Some(scram_auth);
8087
self
8188
}
8289

90+
/// Configures OAuth authentication.
8391
pub fn with_oauth(mut self, oauth: oauth::Oauth) -> Self {
8492
self.oauth = Some(oauth);
8593
self
8694
}
8795

96+
/// Sets a custom PID/secret key generator.
8897
pub fn with_pid_secret_key_generator(
8998
mut self,
9099
generator: Arc<dyn PidSecretKeyGenerator>,
@@ -93,6 +102,7 @@ impl<P> SASLAuthStartupHandler<P> {
93102
self
94103
}
95104

105+
/// Sets a connection manager.
96106
pub fn with_connection_manager(mut self, manager: Arc<ConnectionManager>) -> Self {
97107
self.connection_manager = Some(manager);
98108
self

src/api/auth/sasl/oauth.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ use crate::{
1313
messages::startup::{Authentication, PasswordMessageFamily},
1414
};
1515

16+
/// Re-exports the simple OIDC validator when the feature is enabled.
1617
#[cfg(feature = "simple-oidc-validator")]
1718
pub use crate::api::auth::simple_oidc_validator::SimpleOidcValidator;
1819

20+
/// OAuth/OIDC authentication configuration.
1921
#[derive(Debug)]
2022
pub struct Oauth {
2123
pub issuer: String,
@@ -67,6 +69,7 @@ impl Oauth {
6769
}
6870
}
6971

72+
/// Configures whether to skip user mapping.
7073
pub fn with_skip_usermapping(mut self, skip: bool) -> Self {
7174
self.skip_usermap = skip;
7275
self
@@ -259,6 +262,7 @@ impl Oauth {
259262
Some(token)
260263
}
261264

265+
/// Processes an incoming OAuth SASL message and returns the response and new state.
262266
pub async fn process_oauth_message<C>(
263267
&self,
264268
client: &C,

src/api/auth/sasl/scram.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use x509_certificate::SignatureAlgorithm;
1212
use x509_certificate::certificate::CapturedX509Certificate;
1313

1414
use crate::api::ClientInfo;
15+
/// Re-exports client-side SCRAM authentication types.
1516
#[cfg(feature = "client-api")]
1617
pub use crate::api::auth::sasl::scram::client::*;
1718
use 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")))]
2627
use ring::{digest, hmac, pbkdf2};
2728

29+
/// Default SCRAM iteration count.
2830
pub const SCRAM_ITERATIONS: usize = 4096;
2931

32+
/// SCRAM authentication configuration and state.
3033
#[derive(Debug)]
3134
pub struct ScramAuth {
3235
auth_db: Arc<dyn AuthSource>,
3336
authenticator: ScramServerAuth,
3437
}
3538

3639
impl 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.
8793
pub fn random_nonce() -> String {
8894
STANDARD.encode(rand::random::<[u8; 18]>())
8995
}
@@ -149,6 +155,7 @@ impl Default for ScramServerAuth {
149155
}
150156

151157
impl 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

229236
impl 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
}

src/api/auth/simple_oidc_validator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub struct SimpleOidcValidator {
5656
}
5757

5858
impl SimpleOidcValidator {
59+
/// Creates a new validator by fetching the JWKS URI from the issuer's discovery endpoint.
5960
pub async fn new(issuer: impl Into<String>) -> Result<Self, PgWireError> {
6061
let issuer = issuer.into();
6162
let client = reqwest::Client::new();

src/api/cancel.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ use crate::messages::cancel::CancelRequest;
88
/// Handler for Cancel Request
99
#[async_trait]
1010
pub trait CancelHandler: Send + Sync {
11+
/// Called when a cancel request is received.
1112
async fn on_cancel_request(&self, cancel_request: CancelRequest);
1213
}
1314

15+
/// Default cancel handler that delegates to the connection manager.
1416
#[derive(Debug, derive_new::new)]
1517
pub struct DefaultCancelHandler {
1618
manager: Arc<ConnectionManager>,

src/api/client/auth.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ use crate::messages::{PgWireBackendMessage, PgWireFrontendMessage};
1616

1717
use super::{ClientInfo, ReadyState, ServerInformation};
1818

19+
/// Handler trait for the startup/authentication phase of a client connection.
1920
#[async_trait]
2021
pub trait StartupHandler: Send {
22+
/// Initiate the startup process by sending a startup message.
2123
async fn startup<C>(&mut self, client: &mut C) -> PgWireClientResult<()>
2224
where
2325
C: ClientInfo + Sink<PgWireFrontendMessage> + Unpin + Send,
2426
PgWireClientError: From<<C as Sink<PgWireFrontendMessage>>::Error>;
2527

28+
/// Handle a single backend message during startup/authentication.
2629
async fn on_message<C>(
2730
&mut self,
2831
client: &mut C,
@@ -61,6 +64,7 @@ pub trait StartupHandler: Send {
6164
Ok(ReadyState::Pending)
6265
}
6366

67+
/// Handle an authentication message from the server.
6468
async fn on_authentication<C>(
6569
&mut self,
6670
client: &mut C,
@@ -74,6 +78,7 @@ pub trait StartupHandler: Send {
7478
+ Send,
7579
PgWireClientError: From<<C as Sink<PgWireFrontendMessage>>::Error>;
7680

81+
/// Handle a parameter status message from the server.
7782
async fn on_parameter_status<C>(
7883
&mut self,
7984
client: &mut C,
@@ -83,6 +88,7 @@ pub trait StartupHandler: Send {
8388
C: ClientInfo + Sink<PgWireFrontendMessage> + Unpin + Send,
8489
PgWireClientError: From<<C as Sink<PgWireFrontendMessage>>::Error>;
8590

91+
/// Handle a backend key data message from the server.
8692
async fn on_backend_key<C>(
8793
&mut self,
8894
client: &mut C,
@@ -92,6 +98,7 @@ pub trait StartupHandler: Send {
9298
C: ClientInfo + Sink<PgWireFrontendMessage> + Unpin + Send,
9399
PgWireClientError: From<<C as Sink<PgWireFrontendMessage>>::Error>;
94100

101+
/// Handle a `ReadyForQuery` message and return the collected server information.
95102
async fn on_ready_for_query<C>(
96103
&mut self,
97104
client: &mut C,
@@ -102,6 +109,7 @@ pub trait StartupHandler: Send {
102109
PgWireClientError: From<<C as Sink<PgWireFrontendMessage>>::Error>;
103110
}
104111

112+
/// Default startup handler that supports cleartext, MD5, and SCRAM-SHA-256 authentication.
105113
#[derive(new, Debug)]
106114
pub struct DefaultStartupHandler {
107115
#[new(default)]

0 commit comments

Comments
 (0)