sqlx_core_oldapi/postgres/message/
sasl.rs

1use 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            // name of the SASL authentication mechanism that the client selected
14            buf.put_str_nul(if self.plus {
15                "SCRAM-SHA-256-PLUS"
16            } else {
17                "SCRAM-SHA-256"
18            });
19            let bytes = self.response.as_bytes();
20            let len_i32 = i32::try_from(bytes.len()).expect("buffer too large");
21            buf.extend_from_slice(&len_i32.to_be_bytes());
22            buf.extend_from_slice(bytes);
23        });
24    }
25}
26
27pub struct SaslResponse<'a>(pub &'a str);
28
29impl Encode<'_> for SaslResponse<'_> {
30    fn encode_with(&self, buf: &mut Vec<u8>, _: ()) {
31        buf.push(b'p');
32        buf.put_length_prefixed(|buf| {
33            buf.extend(self.0.as_bytes());
34        });
35    }
36}