mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-12-29 21:00:54 +00:00
add basic dialog authentication
This commit is contained in:
parent
c9197916fb
commit
22e11e59a0
@ -8,11 +8,13 @@ use sqlx_core::{Error, Result};
|
||||
use crate::MySqlDatabaseError;
|
||||
|
||||
mod caching_sha2;
|
||||
mod dialog;
|
||||
mod native;
|
||||
mod rsa;
|
||||
mod sha256;
|
||||
|
||||
pub(crate) use self::caching_sha2::CachingSha2AuthPlugin;
|
||||
pub(crate) use self::dialog::DialogAuthPlugin;
|
||||
pub(crate) use self::native::NativeAuthPlugin;
|
||||
pub(crate) use self::sha256::Sha256AuthPlugin;
|
||||
|
||||
@ -39,6 +41,7 @@ impl dyn AuthPlugin {
|
||||
_ if s == CachingSha2AuthPlugin.name() => Ok(Box::new(CachingSha2AuthPlugin)),
|
||||
_ if s == Sha256AuthPlugin.name() => Ok(Box::new(Sha256AuthPlugin)),
|
||||
_ if s == NativeAuthPlugin.name() => Ok(Box::new(NativeAuthPlugin)),
|
||||
_ if s == DialogAuthPlugin.name() => Ok(Box::new(DialogAuthPlugin)),
|
||||
|
||||
_ => Err(MySqlDatabaseError::new(
|
||||
2059,
|
||||
@ -63,7 +66,8 @@ fn err_msg(plugin: &'static str, message: &str) -> Error {
|
||||
MySqlDatabaseError::new(
|
||||
2061,
|
||||
&format!("Authentication plugin '{}' reported error: {}", plugin, message),
|
||||
).into()
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
fn err<E>(plugin: &'static str, error: &E) -> Error
|
||||
|
||||
33
sqlx-mysql/src/protocol/auth_plugin/dialog.rs
Normal file
33
sqlx-mysql/src/protocol/auth_plugin/dialog.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use bytes::buf::Chain;
|
||||
use bytes::Bytes;
|
||||
use sqlx_core::{Error, Result};
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// Dialog authentication implementation
|
||||
///
|
||||
/// https://mariadb.com/kb/en/authentication-plugin-pam/#dialog
|
||||
///
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct DialogAuthPlugin;
|
||||
|
||||
impl super::AuthPlugin for DialogAuthPlugin {
|
||||
fn name(&self) -> &'static str {
|
||||
"dialog"
|
||||
}
|
||||
|
||||
fn invoke(&self, _nonce: &Chain<Bytes, Bytes>, password: &str) -> Vec<u8> {
|
||||
password.as_bytes().to_vec()
|
||||
}
|
||||
|
||||
fn handle(
|
||||
&self,
|
||||
_data: Bytes,
|
||||
_nonce: &Chain<Bytes, Bytes>,
|
||||
_password: &str,
|
||||
) -> Result<Option<Vec<u8>>> {
|
||||
Err(Error::ConnectOptions {
|
||||
message: Cow::Borrowed("interactive dialog authentication is currently not supported"),
|
||||
source: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user