diff options
22 files changed, 50 insertions, 264 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a77bb299..f0b0283b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,7 +14,7 @@ test: - if ! git diff --quiet ; then echo "Please run 'make -C tool update-usage' and commit the result." ; false ; fi - make -C sqv update-usage - if ! git diff --quiet ; then echo "Please run 'make -C sqv update-usage' and commit the result." ; false ; fi - - cargo clean -p buffered-reader -p sequoia-rfc2822 -p sequoia-openpgp -p sequoia-openpgp-ffi -p sequoia-core -p sequoia-ffi -p sequoia-ffi-macros -p sequoia-ipc -p sequoia-net -p sequoia-store -p sequoia-tool -p sequoia-sqv -p sequoia-guide + - cargo clean -p buffered-reader -p sequoia-openpgp -p sequoia-openpgp-ffi -p sequoia-core -p sequoia-ffi -p sequoia-ffi-macros -p sequoia-ipc -p sequoia-net -p sequoia-store -p sequoia-tool -p sequoia-sqv -p sequoia-guide - find target -type f -atime +7 -delete - du -sh target - du -sh cargo @@ -1583,7 +1583,6 @@ dependencies = [ "sequoia-net 0.10.0", "sequoia-openpgp 0.10.0", "sequoia-openpgp-ffi 0.10.0", - "sequoia-rfc2822 0.10.0", "sequoia-sqv 0.10.0", "sequoia-store 0.10.0", "sequoia-tool 0.10.0", @@ -1675,7 +1674,6 @@ dependencies = [ "rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "sequoia-core 0.10.0", "sequoia-openpgp 0.10.0", - "sequoia-rfc2822 0.10.0", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1701,7 +1699,6 @@ dependencies = [ "quickcheck 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "sequoia-rfc2822 0.10.0", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1721,18 +1718,6 @@ dependencies = [ ] [[package]] -name = "sequoia-rfc2822" -version = "0.10.0" -dependencies = [ - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "lalrpop 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lalrpop-util 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "quickcheck 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "sequoia-sqv" version = "0.10.0" dependencies = [ @@ -25,7 +25,6 @@ maintenance = { status = "actively-developed" } [dependencies] buffered-reader = { path = "buffered-reader", version = "0.10" } -sequoia-rfc2822 = { path = "rfc2822", version = "0.10" } sequoia-openpgp = { path = "openpgp", version = "0.10" } sequoia-openpgp-ffi = { path = "openpgp-ffi", version = "0.10" } sequoia-core = { path = "core", version = "0.10" } diff --git a/doc/release-checklist.md b/doc/release-checklist.md index c0cccaf6..3631fdf1 100644 --- a/doc/release-checklist.md +++ b/doc/release-checklist.md @@ -13,7 +13,6 @@ This is a checklist for doing Sequoia releases. 9. For the following crates, cd into the directory, and do 'cargo publish': - buffered-reader - - rfc2822 - openpgp - sqv 10. In case of errors, correct them, and go back to 6. diff --git a/net/Cargo.toml b/net/Cargo.toml index 4a05a4cd..ea3a1ab8 100644 --- a/net/Cargo.toml +++ b/net/Cargo.toml @@ -24,7 +24,6 @@ maintenance = { status = "actively-developed" } [dependencies] sequoia-openpgp = { path = "../openpgp", version = "0.10", default-features = false } sequoia-core = { path = "../core", version = "0.10" } -sequoia-rfc2822 = { path = "../rfc2822", version = "0.10" } failure = "0.1.2" futures = "0.1" diff --git a/net/src/lib.rs b/net/src/lib.rs index 6b1b10b9..8a37ccc5 100644 --- a/net/src/lib.rs +++ b/net/src/lib.rs @@ -37,7 +37,6 @@ extern crate sequoia_openpgp as openpgp; extern crate sequoia_core; -extern crate sequoia_rfc2822 as rfc2822; #[macro_use] extern crate failure; diff --git a/openpgp/Cargo.toml b/openpgp/Cargo.toml index 066ec065..e787b8eb 100644 --- a/openpgp/Cargo.toml +++ b/openpgp/Cargo.toml @@ -36,7 +36,6 @@ nettle = "5.0.2" quickcheck = { version = "0.9", default-features = false } rand = { version = "0.7", default-features = false } time = "0.1.40" -sequoia-rfc2822 = { path = "../rfc2822", version = "0.10" } [build-dependencies] lalrpop = "0.17" diff --git a/openpgp/src/lib.rs b/openpgp/src/lib.rs index 5f617350..6886e23d 100644 --- a/openpgp/src/lib.rs +++ b/openpgp/src/lib.rs @@ -66,8 +66,6 @@ extern crate rand; extern crate time; -extern crate sequoia_rfc2822 as rfc2822; - #[macro_use] extern crate lazy_static; extern crate idna; diff --git a/openpgp/src/macros.rs b/openpgp/src/macros.rs index e0c640d4..be771a43 100644 --- a/openpgp/src/macros.rs +++ b/openpgp/src/macros.rs @@ -38,6 +38,9 @@ pub(crate) fn indent(i: usize) -> &'static str { } macro_rules! tracer { + ( $TRACE:expr, $func:expr ) => { + tracer!($TRACE, $func, 0) + }; ( $TRACE:expr, $func:expr, $indent:expr ) => { // Currently, Rust doesn't support $( ... ) in a nested // macro's definition. See: diff --git a/openpgp/src/packet/userid.rs b/openpgp/src/packet/userid/mod.rs index eb70d033..36b732f8 100644 --- a/openpgp/src/packet/userid.rs +++ b/openpgp/src/packet/userid/mod.rs @@ -6,18 +6,20 @@ use std::cmp::Ordering; use std::sync::Mutex; use quickcheck::{Arbitrary, Gen}; -use crate::rfc2822::{ +use failure::ResultExt; + +use crate::Result; +use crate::packet; +use crate::Packet; + +mod rfc2822; +use rfc2822::{ AddrSpec, AddrSpecOrOther, Name, NameAddr, NameAddrOrOther, }; -use failure::ResultExt; - -use crate::Result; -use crate::packet; -use crate::Packet; struct ParsedUserID { name: Option<String>, diff --git a/rfc2822/src/component.rs b/openpgp/src/packet/userid/rfc2822/component.rs index 37ea4cbd..801d8303 100644 --- a/rfc2822/src/component.rs +++ b/openpgp/src/packet/userid/rfc2822/component.rs @@ -1,5 +1,5 @@ use lalrpop_util::ParseError; -use crate::lexer::LexicalError; +use super::lexer::LexicalError; /// A UserID value typically looks something like: /// @@ -116,7 +116,7 @@ macro_rules! components_concat { pub(crate) fn components_merge(components: Vec<Component>) -> Vec<Component> { - tracer!(crate::TRACE, "components_merge", 0); + tracer!(super::TRACE, "components_merge", 0); t!("{:?}", components); let mut iter = components.into_iter(); diff --git a/rfc2822/src/grammar.lalrpop b/openpgp/src/packet/userid/rfc2822/grammar.lalrpop index 1b1d2b94..47f626e7 100644 --- a/rfc2822/src/grammar.lalrpop +++ b/openpgp/src/packet/userid/rfc2822/grammar.lalrpop @@ -1,16 +1,16 @@ // -*- mode: Rust; -*- -use crate::parse_error_downcast; -use crate::strings::{ +use super::parse_error_downcast; +use super::strings::{ strings_flatten_into, strings_flatten2, strings_flatten, }; -use crate::component::{ +use super::component::{ Component, components_merge, }; -use crate::lexer; -use crate::lexer::{Token, LexicalError}; +use super::lexer; +use super::lexer::{Token, LexicalError}; // Pass in the original, untokenized input to facilitate error // recovery. See, for instance, the `addr-spec-or-other` production. diff --git a/openpgp/src/packet/userid/rfc2822/grammar.rs b/openpgp/src/packet/userid/rfc2822/grammar.rs new file mode 100644 index 00000000..2e1d8f63 --- /dev/null +++ b/openpgp/src/packet/userid/rfc2822/grammar.rs @@ -0,0 +1,2 @@ +// Include the generated code. +include!(concat!(env!("OUT_DIR"), "/packet/userid/rfc2822/grammar.rs")); diff --git a/rfc2822/src/lexer.rs b/openpgp/src/packet/userid/rfc2822/lexer.rs index 79a609c9..ebdf446d 100644 --- a/rfc2822/src/lexer.rs +++ b/openpgp/src/packet/userid/rfc2822/lexer.rs @@ -105,7 +105,7 @@ impl<'input> Iterator for Lexer<'input> { fn next(&mut self) -> Option<Self::Item> { use self::Token::*; - tracer!(crate::TRACE, "Lexer::next"); + tracer!(super::TRACE, "Lexer::next"); // Returns the length of the first character in s in bytes. // If s is empty, returns 0. diff --git a/rfc2822/src/lib.rs b/openpgp/src/packet/userid/rfc2822/mod.rs index 5d550af6..af4a3ef5 100644 --- a/rfc2822/src/lib.rs +++ b/openpgp/src/packet/userid/rfc2822/mod.rs @@ -19,63 +19,19 @@ //! [OpenPGP implementation]: https://tools.ietf.org/html/rfc4880 //! [User IDs]: https://tools.ietf.org/html/rfc4880#section-5.11 //! [issue]: https://gitlab.com/sequoia-pgp/sequoia/issues -//! -//! # Examples -//! -//! Parsing a [`name-addr`]: -//! -//! ``` -//! use sequoia_rfc2822::NameAddr; -//! -//! let nameaddr = NameAddr::parse( -//! "Professor Pippy P. Poopypants <pippy@jerome-horwitz.k12.oh.us>") -//! .expect("Valid name-addr"); -//! assert_eq!(nameaddr.name(), Some("Professor Pippy P. Poopypants")); -//! assert_eq!(nameaddr.comment(), None); -//! assert_eq!(nameaddr.address(), Some("pippy@jerome-horwitz.k12.oh.us")); -//! -//! // Extra angle brackets. -//! assert!(NameAddr::parse("Invalid <<pippy@jerome-horwitz.k12.oh.us>>") -//! .is_err()); -//! -//! // No angle brackets. -//! assert!(NameAddr::parse("pippy@jerome-horwitz.k12.oh.us") -//! .is_err()); -//! ``` -//! -//! Parsing an [`addr-spec`]: -//! -//! ``` -//! use sequoia_rfc2822::AddrSpec; -//! -//! let addrspec = AddrSpec::parse( -//! "pippy@jerome-horwitz.k12.oh.us") -//! .expect("Valid addr-spec"); -//! assert_eq!(addrspec.address(), "pippy@jerome-horwitz.k12.oh.us"); -//! -//! // Angle brackets are not allowed. -//! assert!(AddrSpec::parse("<pippy@jerome-horwitz.k12.oh.us>") -//! .is_err()); -//! ``` extern crate failure; extern crate lalrpop_util; -#[cfg(test)] #[macro_use] extern crate lazy_static; -#[cfg(test)] #[macro_use] extern crate quickcheck; -#[cfg(test)] extern crate rand; - use lalrpop_util::ParseError; -#[macro_use] mod macros; -#[macro_use] mod trace; mod strings; #[macro_use] mod component; -use crate::component::{ +use component::{ Component }; mod lexer; -use crate::lexer::LexicalError; +use lexer::LexicalError; // We expose a number of productions for testing purposes. // Unfortunately, lalrpop doesn't understand the #[cfg(test)] @@ -88,11 +44,12 @@ mod grammar; mod grammar; #[cfg(test)] +#[allow(non_snake_case)] mod roundtrip; -const TRACE : bool = false; +use crate::Result; -pub type Result<T> = ::std::result::Result<T, failure::Error>; +const TRACE : bool = false; // A failure needs to have a 'static life time. lexer::Tokens don't. // Convert tokens into strings. @@ -129,7 +86,7 @@ fn parse_error_downcast<'a>(e: ParseError<usize, lexer::Token<'a>, LexicalError> } /// A `DisplayName`. -pub struct Name { +pub(crate) struct Name { } impl Name { @@ -138,7 +95,7 @@ impl Name { /// /// Returns an error if `name` contains characters that cannot be /// escaped (NUL, CR and LF). - pub fn escaped<S>(name: S) -> Result<String> + pub(crate) fn escaped<S>(name: S) -> Result<String> where S: AsRef<str> { let name = name.as_ref(); @@ -166,7 +123,7 @@ impl Name { /// /// RFC 2822 comments are ignored. #[derive(Debug, PartialEq, Eq, Clone)] -pub struct AddrSpec { +pub(crate) struct AddrSpec { components: Vec<Component>, } @@ -196,7 +153,7 @@ impl AddrSpec { /// `addr-spec`]. /// /// [RFC 2822 `addr-spec`]: https://tools.ietf.org/html/rfc2822#section-3.4 - pub fn parse<S>(input: S) -> Result<Self> + pub(crate) fn parse<S>(input: S) -> Result<Self> where S: AsRef<str> { let input = input.as_ref(); @@ -212,7 +169,7 @@ impl AddrSpec { } /// Returns the address. - pub fn address(&self) -> &str { + pub(crate) fn address(&self) -> &str { for c in self.components.iter() { if let Component::Address(t) = c { return &t[..]; @@ -255,7 +212,7 @@ impl AddrSpec { /// `ssh://server.example.net`. The parse error can still be obtained /// using `AddrSpecOrOther::address()`. #[derive(Debug, PartialEq, Eq, Clone)] -pub struct AddrSpecOrOther { +pub(crate) struct AddrSpecOrOther { components: Vec<Component>, } @@ -283,7 +240,7 @@ impl AddrSpecOrOther { /// `addr-spec`] or other. /// /// [RFC 2822 `addr-spec`]: https://tools.ietf.org/html/rfc2822#section-3.4 - pub fn parse<S>(input: S) -> Result<Self> + pub(crate) fn parse<S>(input: S) -> Result<Self> where S: AsRef<str> { let input = input.as_ref(); @@ -301,7 +258,7 @@ impl AddrSpecOrOther { /// Returns the address, if any. /// /// If the address is invalid, then the parse error is returned. - pub fn address(&self) -> Result<&str> { + pub(crate) fn address(&self) -> Result<&str> { for c in self.components.iter() { if let Component::Address(t) = c { return Ok(&t[..]); @@ -317,7 +274,7 @@ impl AddrSpecOrOther { /// Returns the invalid address, if any. /// /// If the address is valid, then this returns None. - pub fn other(&self) -> Option<&str> { + pub(crate) fn other(&self) -> Option<&str> { for c in self.components.iter() { if let Component::Address(_) = c { return None; @@ -352,7 +309,7 @@ impl AddrSpecOrOther { /// /// [RFC 2822 `name-addr`]: https://tools.ietf.org/html/rfc2822#section-3.4 #[derive(Debug, PartialEq, Eq, Clone)] -pub struct NameAddr { +pub(crate) struct NameAddr { components: Vec<Component>, } @@ -417,7 +374,7 @@ impl NameAddr { /// `name-addr`]. /// /// [RFC 2822 `name-addr`]: https://tools.ietf.org/html/rfc2822#section-3.4 - pub fn parse<S>(input: S) -> Result<Self> + pub(crate) fn parse<S>(input: S) -> Result<Self> where S: AsRef<str> { let input = input.as_ref(); @@ -435,7 +392,7 @@ impl NameAddr { /// Returns the [display name]. /// /// [display name]: https://tools.ietf.org/html/rfc2822#section-3.4 - pub fn name(&self) -> Option<&str> { + pub(crate) fn name(&self) -> Option<&str> { for c in self.components.iter() { if let Component::Text(t) = c { return Some(&t[..]); @@ -445,7 +402,7 @@ impl NameAddr { } /// Returns the first comment. - pub fn comment(&self) -> Option<&str> { + pub(crate) fn comment(&self) -> Option<&str> { for c in self.components.iter() { if let Component::Comment(t) = c { return Some(&t[..]); @@ -455,7 +412,7 @@ impl NameAddr { } /// Returns the address. - pub fn address(&self) -> Option<&str> { + pub(crate) fn address(&self) -> Option<&str> { for c in self.components.iter() { if let Component::Address(t) = c { return Some(&t[..]); @@ -498,7 +455,7 @@ impl NameAddr { /// `NameAddrOrOther::address()` will return the parse error, and the /// invalid address can be obtained using `NameAddrOrOther::other()`. #[derive(Debug, PartialEq, Eq, Clone)] -pub struct NameAddrOrOther { +pub(crate) struct NameAddrOrOther { components: Vec<Component>, } @@ -558,7 +515,7 @@ impl NameAddrOrOther { /// `name-addr`] with an optionally invalid email address. /// /// [RFC 2822 `name-addr`]: https://tools.ietf.org/html/rfc2822#section-3.4 - pub fn parse<S>(input: S) -> Result<Self> + pub(crate) fn parse<S>(input: S) -> Result<Self> where S: AsRef<str> { let input = input.as_ref(); @@ -576,7 +533,7 @@ impl NameAddrOrOther { /// Returns the [display name]. /// /// [display name]: https://tools.ietf.org/html/rfc2822#section-3.4 - pub fn name(&self) -> Option<&str> { + pub(crate) fn name(&self) -> Option<&str> { for c in self.components.iter() { if let Component::Text(t) = c { return Some(&t[..]); @@ -586,7 +543,7 @@ impl NameAddrOrOther { } /// Returns the first comment. - pub fn comment(&self) -> Option<&str> { + pub(crate) fn comment(&self) -> Option<&str> { for c in self.components.iter() { if let Component::Comment(t) = c { return Some(&t[..]); @@ -598,7 +555,7 @@ impl NameAddrOrOther { /// Returns the address, if any. /// /// If the address is invalid, then the parse error is returned. - pub fn address(&self) -> Result<&str> { + pub(crate) fn address(&self) -> Result<&str> { for c in self.components.iter() { if let Component::Address(t) = c { return Ok(&t[..]); @@ -614,7 +571,7 @@ impl NameAddrOrOther { /// Returns the invalid address, if any. /// /// If the address is valid, then this returns None. - pub fn other(&self) -> Option<&str> { + pub(crate) fn other(&self) -> Option<&str> { for c in self.components.iter() { if let Component::Address(_) = c { return None; diff --git a/rfc2822/src/roundtrip.rs b/openpgp/src/packet/userid/rfc2822/roundtrip.rs index 27cbcaf8..88518c68 100644 --- a/rfc2822/src/roundtrip.rs +++ b/openpgp/src/packet/userid/rfc2822/roundtrip.rs @@ -3,9 +3,9 @@ use std::cmp; use lalrpop_util::ParseError; use quickcheck::{Arbitrary, Gen}; use rand::Rng; -use crate::lexer; -use crate::grammar; -use crate::component::{Component, components_merge}; +use super::lexer; +use super::grammar; +use super::component::{Component, components_merge}; // We put each type of token in its own struct, which contains exactly // one element, a String (e.g., 'Foo(String)'). diff --git a/rfc2822/src/strings.rs b/openpgp/src/packet/userid/rfc2822/strings.rs index bd3e006a..bd3e006a 100644 --- a/rfc2822/src/strings.rs +++ b/openpgp/src/packet/userid/rfc2822/strings.rs diff --git a/rfc2822/README.md b/rfc2822/README.md deleted file mode 100644 index 9467daee..00000000 --- a/rfc2822/README.md +++ /dev/null @@ -1,67 +0,0 @@ -An [RFC 2822] parser. - - [RFC 2822]: https://tools.ietf.org/html/rfc2822 - -Currently, this crate only recognizes the [RFC 2822] [name-addr] and -[addr-spec] productions, i.e., things of the form: - - [name-addr]: https://tools.ietf.org/html/rfc2822#section-3.4 - [addr-spec]: https://tools.ietf.org/html/rfc2822#section-3.4.1 - -``` -Name (Comment) <email@example.org> -``` - -and - -``` -email@example.org -``` - -Although the above appear simple to parse, [RFC 2822]'s whitespace and -comment rules are rather complex. This crate implements the whole -grammar. - -As an extension, in addition to ASCII, we also recognize all UTF-8 -code points. NUL, controls, and specials retain their meaning as -defined in RFC 2822. Other UTF-8 code points are considered to be -text like `a`. - -Further, we also allow dots (`.`) and at symbols (`@`) in the `atom` -production. That is, the `atom` production is extended from: - -``` -atom = [CFWS] 1*atext [CFWS] -``` - -to: - -``` -atom = [CFWS] 1*atext_or_dot_or_at [CFWS] -atext_or_dot_or_at = atext | DOT | AT -``` - -And, as such: - -``` -Professor Pippy P. Poopypants <pippy@jerome-horwitz.k12.oh.us> -``` - -is recognized as a `name-addr` even though [RFC 2822] strictly -requires that the `display-name` be quoted like: - -``` -"Professor Pippy P. Poopypants" <pippy@jerome-horwitz.k12.oh.us> -``` - -Likewise, - -``` -foo@bar.com <foo@bar.com> -``` - -is recognized as a `name-addr` even though the `@` should be quoted. - -This crate does not (yet) implement the new [RFC 5322]. - - [RFC 5322]: https://tools.ietf.org/html/rfc5322 diff --git a/rfc2822/build.rs b/rfc2822/build.rs deleted file mode 100644 index 23c7d3f8..00000000 --- a/rfc2822/build.rs +++ /dev/null @@ -1,5 +0,0 @@ -extern crate lalrpop; - -fn main() { - lalrpop::process_root().unwrap(); -} diff --git a/rfc2822/src/grammar.rs b/rfc2822/src/grammar.rs deleted file mode 100644 index 433715d4..00000000 --- a/rfc2822/src/grammar.rs +++ /dev/null @@ -1,2 +0,0 @@ -// Include the generated code. -include!(concat!(env!("OUT_DIR"), "/grammar.rs")); diff --git a/rfc2822/src/macros.rs b/rfc2822/src/macros.rs deleted file mode 100644 index 9418f2e2..00000000 --- a/rfc2822/src/macros.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Turns an `if let` into an expression so that it is possible to do -// things like: -// -// ```rust,nocompile -// if destructures_to(Foo::Bar(_) = value) -// || destructures_to(Foo::Bam(_) = value) { ... } -// ``` -macro_rules! destructures_to { - ( $error: pat = $expr:expr ) => { - { - let x = $expr; - if let $error = x { - true - } else { - false - } - } - }; -} diff --git a/rfc2822/src/trace.rs b/rfc2822/src/trace.rs deleted file mode 100644 index c93e1e04..00000000 --- a/rfc2822/src/trace.rs +++ /dev/null @@ -1,63 +0,0 @@ -use std::cmp; - -macro_rules! trace { |