Update to nom 6

This commit is contained in:
Damian Poddebniak 2021-02-22 16:33:18 +01:00
parent 75d09f91ec
commit cc8551e357
5 changed files with 24 additions and 25 deletions

View File

@ -7,5 +7,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
nom = "5.1" nom = "6"
abnf-core = "0.3.0" abnf-core = "0.4.0"

View File

@ -17,7 +17,7 @@ use nom::{
}; };
pub fn command(input: &[u8]) -> IResult<&[u8], Command> { pub fn command(input: &[u8]) -> IResult<&[u8], Command> {
let parser = alt(( let mut parser = alt((
helo, ehlo, mail, rcpt, data, rset, vrfy, expn, help, noop, quit, helo, ehlo, mail, rcpt, data, rset, vrfy, expn, help, noop, quit,
starttls, // Extensions starttls, // Extensions
auth_login, // https://interoperability.blob.core.windows.net/files/MS-XLOGIN/[MS-XLOGIN].pdf auth_login, // https://interoperability.blob.core.windows.net/files/MS-XLOGIN/[MS-XLOGIN].pdf
@ -31,7 +31,7 @@ pub fn command(input: &[u8]) -> IResult<&[u8], Command> {
/// helo = "HELO" SP Domain CRLF /// helo = "HELO" SP Domain CRLF
pub fn helo(input: &[u8]) -> IResult<&[u8], Command> { pub fn helo(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple(( let mut parser = tuple((
tag_no_case(b"HELO"), tag_no_case(b"HELO"),
SP, SP,
alt((Domain, address_literal)), // address_literal alternative for Geary alt((Domain, address_literal)), // address_literal alternative for Geary
@ -50,7 +50,7 @@ pub fn helo(input: &[u8]) -> IResult<&[u8], Command> {
/// ehlo = "EHLO" SP ( Domain / address-literal ) CRLF /// ehlo = "EHLO" SP ( Domain / address-literal ) CRLF
pub fn ehlo(input: &[u8]) -> IResult<&[u8], Command> { pub fn ehlo(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple(( let mut parser = tuple((
tag_no_case(b"EHLO"), tag_no_case(b"EHLO"),
SP, SP,
alt((Domain, address_literal)), alt((Domain, address_literal)),
@ -69,7 +69,7 @@ pub fn ehlo(input: &[u8]) -> IResult<&[u8], Command> {
/// mail = "MAIL FROM:" Reverse-path [SP Mail-parameters] CRLF /// mail = "MAIL FROM:" Reverse-path [SP Mail-parameters] CRLF
pub fn mail(input: &[u8]) -> IResult<&[u8], Command> { pub fn mail(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple(( let mut parser = tuple((
tag_no_case(b"MAIL FROM:"), tag_no_case(b"MAIL FROM:"),
opt(SP), // Out-of-Spec, but Outlook does it ... opt(SP), // Out-of-Spec, but Outlook does it ...
Reverse_path, Reverse_path,
@ -94,7 +94,7 @@ pub fn mail(input: &[u8]) -> IResult<&[u8], Command> {
/// local-parts, the "Postmaster" string shown above is /// local-parts, the "Postmaster" string shown above is
/// treated as case-insensitive. /// treated as case-insensitive.
pub fn rcpt(input: &[u8]) -> IResult<&[u8], Command> { pub fn rcpt(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple(( let mut parser = tuple((
tag_no_case(b"RCPT TO:"), tag_no_case(b"RCPT TO:"),
opt(SP), // Out-of-Spec, but Outlook does it ... opt(SP), // Out-of-Spec, but Outlook does it ...
alt(( alt((
@ -119,7 +119,7 @@ pub fn rcpt(input: &[u8]) -> IResult<&[u8], Command> {
/// data = "DATA" CRLF /// data = "DATA" CRLF
pub fn data(input: &[u8]) -> IResult<&[u8], Command> { pub fn data(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"DATA"), CRLF)); let mut parser = tuple((tag_no_case(b"DATA"), CRLF));
let (remaining, _) = parser(input)?; let (remaining, _) = parser(input)?;
@ -128,7 +128,7 @@ pub fn data(input: &[u8]) -> IResult<&[u8], Command> {
/// rset = "RSET" CRLF /// rset = "RSET" CRLF
pub fn rset(input: &[u8]) -> IResult<&[u8], Command> { pub fn rset(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"RSET"), CRLF)); let mut parser = tuple((tag_no_case(b"RSET"), CRLF));
let (remaining, _) = parser(input)?; let (remaining, _) = parser(input)?;
@ -137,7 +137,7 @@ pub fn rset(input: &[u8]) -> IResult<&[u8], Command> {
/// vrfy = "VRFY" SP String CRLF /// vrfy = "VRFY" SP String CRLF
pub fn vrfy(input: &[u8]) -> IResult<&[u8], Command> { pub fn vrfy(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"VRFY"), SP, String, CRLF)); let mut parser = tuple((tag_no_case(b"VRFY"), SP, String, CRLF));
let (remaining, (_, _, data, _)) = parser(input)?; let (remaining, (_, _, data, _)) = parser(input)?;
@ -151,7 +151,7 @@ pub fn vrfy(input: &[u8]) -> IResult<&[u8], Command> {
/// expn = "EXPN" SP String CRLF /// expn = "EXPN" SP String CRLF
pub fn expn(input: &[u8]) -> IResult<&[u8], Command> { pub fn expn(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"EXPN"), SP, String, CRLF)); let mut parser = tuple((tag_no_case(b"EXPN"), SP, String, CRLF));
let (remaining, (_, _, data, _)) = parser(input)?; let (remaining, (_, _, data, _)) = parser(input)?;
@ -165,7 +165,7 @@ pub fn expn(input: &[u8]) -> IResult<&[u8], Command> {
/// help = "HELP" [ SP String ] CRLF /// help = "HELP" [ SP String ] CRLF
pub fn help(input: &[u8]) -> IResult<&[u8], Command> { pub fn help(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"HELP"), opt(preceded(SP, String)), CRLF)); let mut parser = tuple((tag_no_case(b"HELP"), opt(preceded(SP, String)), CRLF));
let (remaining, (_, maybe_data, _)) = parser(input)?; let (remaining, (_, maybe_data, _)) = parser(input)?;
@ -179,7 +179,7 @@ pub fn help(input: &[u8]) -> IResult<&[u8], Command> {
/// noop = "NOOP" [ SP String ] CRLF /// noop = "NOOP" [ SP String ] CRLF
pub fn noop(input: &[u8]) -> IResult<&[u8], Command> { pub fn noop(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"NOOP"), opt(preceded(SP, String)), CRLF)); let mut parser = tuple((tag_no_case(b"NOOP"), opt(preceded(SP, String)), CRLF));
let (remaining, (_, maybe_data, _)) = parser(input)?; let (remaining, (_, maybe_data, _)) = parser(input)?;
@ -193,7 +193,7 @@ pub fn noop(input: &[u8]) -> IResult<&[u8], Command> {
/// quit = "QUIT" CRLF /// quit = "QUIT" CRLF
pub fn quit(input: &[u8]) -> IResult<&[u8], Command> { pub fn quit(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"QUIT"), CRLF)); let mut parser = tuple((tag_no_case(b"QUIT"), CRLF));
let (remaining, _) = parser(input)?; let (remaining, _) = parser(input)?;
@ -201,7 +201,7 @@ pub fn quit(input: &[u8]) -> IResult<&[u8], Command> {
} }
pub fn starttls(input: &[u8]) -> IResult<&[u8], Command> { pub fn starttls(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"STARTTLS"), CRLF)); let mut parser = tuple((tag_no_case(b"STARTTLS"), CRLF));
let (remaining, _) = parser(input)?; let (remaining, _) = parser(input)?;
@ -220,7 +220,7 @@ pub fn starttls(input: &[u8]) -> IResult<&[u8], Command> {
/// auth_login_password_challenge = "334 UGFzc3dvcmQ6" CRLF /// auth_login_password_challenge = "334 UGFzc3dvcmQ6" CRLF
/// auth_login_password_response = password CRLF /// auth_login_password_response = password CRLF
pub fn auth_login(input: &[u8]) -> IResult<&[u8], Command> { pub fn auth_login(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple(( let mut parser = tuple((
tag_no_case(b"AUTH"), tag_no_case(b"AUTH"),
SP, SP,
tag_no_case("LOGIN"), tag_no_case("LOGIN"),
@ -237,7 +237,7 @@ pub fn auth_login(input: &[u8]) -> IResult<&[u8], Command> {
} }
pub fn auth_plain(input: &[u8]) -> IResult<&[u8], Command> { pub fn auth_plain(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple(( let mut parser = tuple((
tag_no_case(b"AUTH"), tag_no_case(b"AUTH"),
SP, SP,
tag_no_case("PLAIN"), tag_no_case("PLAIN"),
@ -420,7 +420,7 @@ pub fn Ldh_str(input: &[u8]) -> IResult<&[u8], &[u8]> {
/// ) "]" /// ) "]"
/// ; See Section 4.1.3 /// ; See Section 4.1.3
pub fn address_literal(input: &[u8]) -> IResult<&[u8], &str> { pub fn address_literal(input: &[u8]) -> IResult<&[u8], &str> {
let parser = delimited( let mut parser = delimited(
tag(b"["), tag(b"["),
map_res( map_res(
alt(( alt((

View File

@ -23,7 +23,7 @@ fn is_base64_char(i: u8) -> bool {
} }
pub fn base64(input: &[u8]) -> IResult<&[u8], &str> { pub fn base64(input: &[u8]) -> IResult<&[u8], &str> {
let parser = map_res( let mut parser = map_res(
recognize(tuple(( recognize(tuple((
take_while(is_base64_char), take_while(is_base64_char),
opt(alt((tag("=="), tag("=")))), opt(alt((tag("=="), tag("=")))),

View File

@ -19,7 +19,7 @@ use nom::{
/// *( "220-" [ textstring ] CRLF ) /// *( "220-" [ textstring ] CRLF )
/// "220" [ SP textstring ] CRLF ) /// "220" [ SP textstring ] CRLF )
pub fn Greeting(input: &[u8]) -> IResult<&[u8], GreetingType> { pub fn Greeting(input: &[u8]) -> IResult<&[u8], GreetingType> {
let parser = alt(( let mut parser = alt((
map( map(
tuple(( tuple((
tag(b"220 "), tag(b"220 "),

View File

@ -1,11 +1,10 @@
use crate::{parse::command::Domain, types::EhloOkResp}; use crate::{parse::command::Domain, types::EhloOkResp};
use abnf_core::streaming::{is_ALPHA, is_DIGIT, CRLF, SP}; use abnf_core::streaming::{is_ALPHA, is_DIGIT, CRLF, SP};
use nom::multi::separated_list;
use nom::{ use nom::{
branch::alt, branch::alt,
bytes::streaming::{tag, take_while, take_while1, take_while_m_n}, bytes::streaming::{tag, take_while, take_while1, take_while_m_n},
combinator::{map, map_res, opt, recognize}, combinator::{map, map_res, opt, recognize},
multi::many0, multi::{many0, separated_list0},
sequence::{delimited, preceded, tuple}, sequence::{delimited, preceded, tuple},
IResult, IResult,
}; };
@ -17,7 +16,7 @@ use nom::{
/// ///
/// Edit: collapsed ("250" SP) to ("250 ") /// Edit: collapsed ("250" SP) to ("250 ")
pub fn ehlo_ok_rsp(input: &[u8]) -> IResult<&[u8], EhloOkResp> { pub fn ehlo_ok_rsp(input: &[u8]) -> IResult<&[u8], EhloOkResp> {
let parser = alt(( let mut parser = alt((
map( map(
tuple((tag(b"250 "), Domain, opt(preceded(SP, ehlo_greet)), CRLF)), tuple((tag(b"250 "), Domain, opt(preceded(SP, ehlo_greet)), CRLF)),
|(_, domain, maybe_ehlo, _)| EhloOkResp { |(_, domain, maybe_ehlo, _)| EhloOkResp {
@ -87,11 +86,11 @@ pub fn ehlo_greet(input: &[u8]) -> IResult<&[u8], &str> {
/// ///
/// TODO: SMTP servers often respond with "AUTH=LOGIN PLAIN". Why? /// TODO: SMTP servers often respond with "AUTH=LOGIN PLAIN". Why?
pub fn ehlo_line(input: &[u8]) -> IResult<&[u8], (&str, Vec<&str>)> { pub fn ehlo_line(input: &[u8]) -> IResult<&[u8], (&str, Vec<&str>)> {
let parser = tuple(( let mut parser = tuple((
map_res(ehlo_keyword, std::str::from_utf8), map_res(ehlo_keyword, std::str::from_utf8),
opt(preceded( opt(preceded(
alt((SP, tag("="))), // TODO: For Outlook? alt((SP, tag("="))), // TODO: For Outlook?
separated_list(SP, ehlo_param), separated_list0(SP, ehlo_param),
)), )),
)); ));