mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-11-03 06:52:48 +00:00
WIP: Work on PasswordMessage and StartupMessage
This commit is contained in:
parent
d3121c60cf
commit
6c02124eab
@ -7,6 +7,8 @@ mod encode;
|
|||||||
mod message;
|
mod message;
|
||||||
mod ready_for_query;
|
mod ready_for_query;
|
||||||
mod response;
|
mod response;
|
||||||
|
mod startup_message;
|
||||||
|
mod password_message;
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
decode::Decode,
|
decode::Decode,
|
||||||
@ -14,4 +16,6 @@ pub use self::{
|
|||||||
message::Message,
|
message::Message,
|
||||||
ready_for_query::{ReadyForQuery, TransactionStatus},
|
ready_for_query::{ReadyForQuery, TransactionStatus},
|
||||||
response::{Response, ResponseBuilder, Severity},
|
response::{Response, ResponseBuilder, Severity},
|
||||||
|
startup_message::StartupMessage,
|
||||||
|
password_message::PasswordMessage,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -40,7 +40,6 @@ impl Decode for Message {
|
|||||||
let src = src.slice(pos, pos + len - 4);
|
let src = src.slice(pos, pos + len - 4);
|
||||||
|
|
||||||
Ok(match token {
|
Ok(match token {
|
||||||
// FIXME: These tokens are duplicated here and in the respective encode functions
|
|
||||||
b'N' | b'E' => Message::Response(Response::decode(src)?),
|
b'N' | b'E' => Message::Response(Response::decode(src)?),
|
||||||
b'Z' => Message::ReadyForQuery(ReadyForQuery::decode(src)?),
|
b'Z' => Message::ReadyForQuery(ReadyForQuery::decode(src)?),
|
||||||
|
|
||||||
|
|||||||
49
mason-postgres-protocol/src/password_message.rs
Normal file
49
mason-postgres-protocol/src/password_message.rs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
use bytes::Bytes;
|
||||||
|
use std::io;
|
||||||
|
use crate::{Encode, Decode};
|
||||||
|
|
||||||
|
pub struct PasswordMessage {
|
||||||
|
password: Bytes,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PasswordMessage {
|
||||||
|
pub fn cleartext(s: impl AsRef<str>) -> Self {
|
||||||
|
// TODO
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn md5(s: impl AsRef<str>) -> Self {
|
||||||
|
// TODO
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The password (encrypted, if requested).
|
||||||
|
pub fn password(&self) -> &[u8] {
|
||||||
|
&self.password
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Decode for PasswordMessage {
|
||||||
|
fn decode(src: Bytes) -> io::Result<Self> where
|
||||||
|
Self: Sized {
|
||||||
|
// There is only one field, the password, and it's not like we can
|
||||||
|
// decrypt it if it was encrypted
|
||||||
|
Ok(PasswordMessage { password: src })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Encode for PasswordMessage {
|
||||||
|
fn size_hint(&self) -> usize {
|
||||||
|
self.password.len() + 5
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encode(&self, buf: &mut Vec<u8>) -> io::Result<()> {
|
||||||
|
buf.push(b'p');
|
||||||
|
buf.copy_from_slice((self.password.len() + 4).to_be_bytes());
|
||||||
|
buf.copy_from_slice(&self.password);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Encode and Decode tests
|
||||||
8
mason-postgres-protocol/src/startup_message.rs
Normal file
8
mason-postgres-protocol/src/startup_message.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
use bytes::Bytes;
|
||||||
|
use std::io;
|
||||||
|
use crate::{Encode, Decode};
|
||||||
|
|
||||||
|
pub struct StartupMessage {
|
||||||
|
version: u32,
|
||||||
|
params: Bytes,
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user