Skip to content

Commit

Permalink
Add security multiparts for MIME (RFC 1847)
Browse files Browse the repository at this point in the history
- 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 hyperium#113.
  • Loading branch information
juga authored and Azul committed Jan 14, 2020
1 parent 938484d commit 2ec0ba3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
19 changes: 18 additions & 1 deletion mime-parse/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,15 @@ impl Atoms {
if sub == OCTET_STREAM {
return Atoms::APPLICATION_OCTET_STREAM;
}
}
},
13 => {
if sub == PGP_ENCRYPTED {
return Atoms::APPLICATION_PGP_ENCRYPTED;
}
if sub == PGP_SIGNATURE {
return Atoms::APPLICATION_PGP_SIGNATURE;
}
},
21 => {
if sub == WWW_FORM_URLENCODED {
return Atoms::APPLICATION_WWW_FORM_URLENCODED;
Expand Down Expand Up @@ -407,12 +415,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";
Expand Down Expand Up @@ -466,6 +481,8 @@ mimes! {
APPLICATION_MSGPACK, "application/msgpack", 11;
APPLICATION_PDF, "application/pdf", 11;
APPLICATION_DNS, "application/dns-message", 11;
APPLICATION_PGP_ENCRYPTED, "application/pgp-encrypted", 11;
APPLICATION_PGP_SIGNATURE, "application/pgp-signature", 11;

// media-ranges
//@ MediaRange:
Expand Down
2 changes: 2 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ mod tests {
assert_eq!(mt.param("boundary").unwrap(), "AbCd");
}

#[test]
fn multipart_type_protocol_param() {
let me = media_type!("multipart/encrypted; protocol=\"application/pgp-encrypted\"");
assert_eq!(me.type_(), MULTIPART);
assert_eq!(me.subtype(), ENCRYPTED);
assert_eq!(me.param("protocol").unwrap(), &APPLICATION_PGP_ENCRYPTED.to_string()[..]);
}


#[test]
fn media_type_lowercase() {
let mt = media_type!("MULTIPART/FORM-DATA; BOUNDARY=AbCd");
Expand Down

0 comments on commit 2ec0ba3

Please sign in to comment.