From 7634c979b7abee8f1a36bb1fa74c44d52d2bceb5 Mon Sep 17 00:00:00 2001 From: juga Date: Wed, 29 May 2019 10:09:07 +0000 Subject: [PATCH] Add security multiparts for MIME (RFC 1847) - Add `encrypted` multipart subtype - Add `pgp-encrypted` application subtype - Add `application/pgp-encrypted` type - Add `signed` multipart subtype - Add `pgp-signature` application subtype - Add `application/pgp-signature` type Closes #113. --- mime-parse/src/constants.rs | 20 ++++++++++++++++++++ src/constants.rs | 2 ++ src/macros.rs | 10 ++++++++++ 3 files changed, 32 insertions(+) diff --git a/mime-parse/src/constants.rs b/mime-parse/src/constants.rs index 634c2bf3..76424a51 100644 --- a/mime-parse/src/constants.rs +++ b/mime-parse/src/constants.rs @@ -331,6 +331,16 @@ impl Atoms { return Atoms::APPLICATION_OCTET_STREAM; } } + // 13 => { + // if sub == PGP_ENCRYPTED [ + // return Atoms::APPLICATION_PGP_ENCRYPTED; + // ] + // } + // 13 => { + // if sub == PGP_SIGNATURE [ + // return Atoms::APPLICATION_PGP_SIGNATURE; + // ] + // } 21 => { if sub == WWW_FORM_URLENCODED { return Atoms::APPLICATION_WWW_FORM_URLENCODED; @@ -407,12 +417,19 @@ names! { OCTET_STREAM, "octet-stream"; PDF, "pdf"; + // Security Multiparts for MIME (RFC 1847) + PGP_ENCRYPTED, "pgp-encrypted"; + PGP_SIGNATURE, "pgp-signature"; + // common font/* WOFF, "woff"; WOFF2, "woff2"; // multipart/* FORM_DATA, "form-data"; + // Security Multiparts for MIME (RFC 1847) + ENCRYPTED, "encrypted"; + SIGNED, "signed"; // common image/* BMP, "bmp"; @@ -466,6 +483,9 @@ mimes! { APPLICATION_MSGPACK, "application/msgpack", 11; APPLICATION_PDF, "application/pdf", 11; APPLICATION_DNS, "application/dns-message", 11; + // Security Multiparts for MIME (RFC 1847) + APPLICATION_PGP_ENCRYPTED, "application/pgp-encrypted", 11; + APPLICATION_PGP_SIGNATURE, "application/pgp-signature", 11; // media-ranges //@ MediaRange: diff --git a/src/constants.rs b/src/constants.rs index af4376ec..3408c22d 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -109,6 +109,8 @@ mimes! { APPLICATION_MSGPACK, "application/msgpack"; APPLICATION_PDF, "application/pdf"; APPLICATION_DNS, "application/dns-message"; + APPLICATION_PGP_ENCRYPTED, "application/pgp-encrypted"; + APPLICATION_PGP_SIGNATURE, "application/pgp-signature"; // media-ranges @ MediaRange: diff --git a/src/macros.rs b/src/macros.rs index 0e851b48..59524366 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -121,6 +121,16 @@ mod tests { assert_eq!(mt.param("boundary").unwrap(), "AbCd"); } + #[test] + fn multipart_type_two_param() { + let me = media_type!("multipart/encrypted; protocol=\"application/pgp-encrypted\"; boundary=\"jtjy1\""); + assert_eq!(me.type(), MULTIPART); + assert_eq!(me.subtype(, ENCRYPTED); + assert_eq!(me.param("boundary").unwrap(), "jtjy1"); + assert_eq!(me.param("protocol").unwrap(), APPPLICATION_PGP_ENCRYTPED); + } + + #[test] fn media_type_lowercase() { let mt = media_type!("MULTIPART/FORM-DATA; BOUNDARY=AbCd");