sqlx_core_guts/postgres/message/
sasl.rs1use crate::io::{BufMutExt, Encode};
2use crate::postgres::io::PgBufMutExt;
3
4pub struct SaslInitialResponse<'a> {
5 pub response: &'a str,
6 pub plus: bool,
7}
8
9impl Encode<'_> for SaslInitialResponse<'_> {
10 fn encode_with(&self, buf: &mut Vec<u8>, _: ()) {
11 buf.push(b'p');
12 buf.put_length_prefixed(|buf| {
13 buf.put_str_nul(if self.plus {
15 "SCRAM-SHA-256-PLUS"
16 } else {
17 "SCRAM-SHA-256"
18 });
19
20 buf.extend(&(self.response.as_bytes().len() as i32).to_be_bytes());
21 buf.extend(self.response.as_bytes());
22 });
23 }
24}
25
26pub struct SaslResponse<'a>(pub &'a str);
27
28impl Encode<'_> for SaslResponse<'_> {
29 fn encode_with(&self, buf: &mut Vec<u8>, _: ()) {
30 buf.push(b'p');
31 buf.put_length_prefixed(|buf| {
32 buf.extend(self.0.as_bytes());
33 });
34 }
35}