| Index: net/base/mime_util.cc
|
| diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc
|
| index 0d511201fd0cdfdda126ad480bc0157e5385e33f..97c7e001c53ad7d9fd8e498e6dbc3893bdb34c3b 100644
|
| --- a/net/base/mime_util.cc
|
| +++ b/net/base/mime_util.cc
|
| @@ -7,9 +7,11 @@
|
| #include <map>
|
| #include <string>
|
|
|
| +#include "base/base64.h"
|
| #include "base/containers/hash_tables.h"
|
| #include "base/lazy_instance.h"
|
| #include "base/logging.h"
|
| +#include "base/rand_util.h"
|
| #include "base/stl_util.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_split.h"
|
| @@ -561,6 +563,44 @@ void GetExtensionsForMimeType(
|
| HashSetToVector(&unique_extensions, extensions);
|
| }
|
|
|
| +NET_EXPORT std::string GenerateMimeMultipartBoundary() {
|
| + // Based on RFC 1341, section "7.2.1 Multipart: The common syntax":
|
| + // Because encapsulation boundaries must not appear in the body parts being
|
| + // encapsulated, a user agent must exercise care to choose a unique
|
| + // boundary. The boundary in the example above could have been the result of
|
| + // an algorithm designed to produce boundaries with a very low probability
|
| + // of already existing in the data to be encapsulated without having to
|
| + // prescan the data.
|
| + // [...]
|
| + // the boundary parameter [...] consists of 1 to 70 characters from a set of
|
| + // characters known to be very robust through email gateways, and NOT ending
|
| + // with white space.
|
| + // [...]
|
| + // boundary := 0*69<bchars> bcharsnospace
|
| + // bchars := bcharsnospace / " "
|
| + // bcharsnospace := DIGIT / ALPHA / "'" / "(" / ")" / "+" /
|
| + // "_" / "," / "-" / "." / "/" / ":" / "=" / "?"
|
| +
|
| + char random_values[30];
|
| + base::RandBytes(random_values, sizeof(random_values));
|
| +
|
| + // Allowed base64 characters are a subset of bcharnospace above:
|
| + // base64char := DIGIT / ALPHA / "+" / "/" / "="
|
| + // ("=" is used for padding which won't apply here).
|
| + std::string random_base64;
|
| + base::Base64Encode(base::StringPiece(random_values, sizeof(random_values)),
|
| + &random_base64);
|
| +
|
| + std::string result("----MultipartBoundary--");
|
| + result.append(random_base64);
|
| + result.append("----");
|
| +
|
| + // Not a strict requirement - documentation only.
|
| + DCHECK_EQ(67u, result.size());
|
| +
|
| + return result;
|
| +}
|
| +
|
| void AddMultipartValueForUpload(const std::string& value_name,
|
| const std::string& value,
|
| const std::string& mime_boundary,
|
|
|