fix generate_boundary #14

Merged
zyddnys merged 2 commits from master into master 2021-04-13 11:24:21 +12:00
zyddnys commented 2021-04-08 14:10:32 +12:00 (Migrated from github.com)

Replace standard base64 encoding with URL safe version for generating boundary which only consists of alphanumeric US-ASCII characters, underscore and -
Despite = being allowed, many multipart implementations do not quote boundary in Content-Type, so it is safe to remove = from result.

Replace standard base64 encoding with URL safe version for generating boundary which only consists of alphanumeric US-ASCII characters, underscore and - Despite = being allowed, many multipart implementations do not quote boundary in Content-Type, so it is safe to remove = from result.
mikedilger commented 2021-04-10 10:28:06 +12:00 (Migrated from github.com)

'/' apparently also can be a problem in some implementations if unquoted in the header.

I'd prefer to map "=" onto "-" (which occurs always at the end, and I've seen examples in the RFCs with hyphens at the end and the grammar certainly allows that) and map "/" onto "." (which seems the next least problematic character) and leave the "+" from standard base64 as is. That way the boundaries remain unique since those characters were not used yet, and we preserve the can-never-repeat property of textnonce.

Let me know if that is satisfactory.

  TextNonce::sized(68).unwrap().into_string().into_bytes().iter().map(|&ch| {
        if ch==b'=' { return b'-'; }
        else if ch==b'/' { return b'.'; }
        else { return ch; }
    }).collect()
'/' apparently also can be a problem in some implementations if unquoted in the header. I'd prefer to map "=" onto "-" (which occurs always at the end, and I've seen examples in the RFCs with hyphens at the end and the grammar certainly allows that) and map "/" onto "." (which seems the next least problematic character) and leave the "+" from standard base64 as is. That way the boundaries remain unique since those characters were not used yet, and we preserve the can-never-repeat property of textnonce. Let me know if that is satisfactory. ````rust TextNonce::sized(68).unwrap().into_string().into_bytes().iter().map(|&ch| { if ch==b'=' { return b'-'; } else if ch==b'/' { return b'.'; } else { return ch; } }).collect() ````
zyddnys commented 2021-04-11 11:03:55 +12:00 (Migrated from github.com)

Now I made = to - and / to .

Now I made = to - and / to .
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mikedilger/mime-multipart!14
No description provided.