Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_net/src/mail/sasl.rs

1.2 KiB, 1 run

created by r18615380:77332, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! SASL responses the mail servers accept: PLAIN (RFC 4616) and LOGIN, shared by SMTP `AUTH`
2//! and IMAP `AUTHENTICATE`.
3//!
4//! [Written with AI entirely](https://need2know.ai/entirely-ai/code)\
5//! Anthropic Claude
6
7pub const LOGIN_USER_PROMPT: &[u8] = b"Username:"; // fixed: the LOGIN mechanism's challenges
8pub const LOGIN_PASS_PROMPT: &[u8] = b"Password:";
9
10/// The account and password of a decoded PLAIN response, `authzid NUL authcid NUL passwd`.
11/// An authzid other than the authcid is refused, because no account may act as another.
12pub fn plain_credentials(raw: &[u8]) -> Option<(String, String)> {
13 let mut parts = raw.split(|b| *b == 0u8);
14 let (Some(z), Some(c), Some(p)) = (parts.next(), parts.next(), parts.next()) else {
15 return None;
16 };
17 let (Ok(authzid), Ok(authcid), Ok(passwd)) = (
18 std::str::from_utf8(z),
19 String::from_utf8(c.to_vec()),
20 String::from_utf8(p.to_vec()),
21 ) else {
22 return None;
23 };
24 if parts.next().is_some() || authcid.is_empty() || passwd.is_empty() {
25 return None;
26 }
27 if !authzid.is_empty() && !authzid.eq_ignore_ascii_case(&authcid) {
28 return None;
29 }
30 Some((authcid, passwd))
31}