New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support base64 and base32768 file name encoding for crypt. #5802
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put some initial comments inline.
This should probably also have some tests in backend/crypt/crypt_test.go
to run the backend tests against the new file name encoding.
I'm going to allow the CI to run now - expect some linting problems you'll need to fix up!
backend/crypt/cipher.go
Outdated
DecodeString(s string) ([]byte, error) | ||
} | ||
|
||
type CaseInsensitiveBase32Encoding struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems over complicated to me....
I'd suggest you define this (note lower case so we don't make a public symbol)
type caseInsensitiveBase32Encoding struct {}
Then define the two methods
func (_ caseInsensitiveBase32Encoding) EncodeToString(src []byte) string {
// contents the same as encodeFileName in original source
}
func (_ caseInsensitiveBase32Encoding) DecodeString(s string) ([]byte, error) {
// contents the same as decodeFileName in original source
}
And finally check it satisfies the interface
var _ StrEncoding = caseInsensitiveBase32Encoding{}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed this change is modifying codes that already work. I reverted the base32 implementation in 79817be.
backend/crypt/cipher.go
Outdated
@@ -114,22 +117,65 @@ func (mode NameEncryptionMode) String() (out string) { | |||
return out | |||
} | |||
|
|||
// Cipher defines an encoding and decoding cipher for the crypt backend | |||
// StrEncoding is encoding methods dealing with strings | |||
type StrEncoding interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be called filenameEncoding
- initial lower so it isn't exported and more specific name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry about this. Fixed in 2767ee3.
backend/crypt/cipher.go
Outdated
s = strings.ToLower(s) | ||
switch s { | ||
case "base32": | ||
base32hex := base32.NewEncoding(encodeHexLower) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...this then becomes
enc = caseInsensitiveBase32Encoding{}
I also added some new fstests in |
Linting problems should now be fixed in fb0fb43. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great now - thank you.
Can you rebase it on master, fix the conflicts and squash it down to two commits - one for Max-Sum's work and one for your work.
(can you make sure Max-Sum commit compiles on its own - if it doesn't fix it!)
I'll merge it then - thank you.
PS If any of this git stuff is too much for you then I can do it easily enough.
fb0fb43
to
1bd9007
Compare
There is another thing to note: Currently there is a failing test case in
I' m not very certain if such a failure is expected or something went wrong. Maybe I should open another issue about this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks great now - thank you - I will merge now.
...actually I will wait for the CI to complete before merging! |
That is very interesting - thank you. What that shows up is that test isn't being run on the CI, nor in the integration tests which is a bit of an oversight, so thank you for bringing it to my attention. I'll fix the test not being run and the test itself shortly :-) |
Onedrive used to have a bug on processing special characters. Microsft ignores this issue and therefor I didn't continue on developing this. Sorry for that. |
What is the purpose of this change?
This PR add support for base64 and base32768 file name encoding for crypt. This resolves #5801 and relieve the problem of file name length being too long when encrypted.
It is based on the commit 78cab2b by @Max-Sum . For other changes in https://github.com/Max-Sum/rclone/commits/compress_crypted_filename, I' m worried that some of them might break backward compatibility or involving security issue, and I' m not very familiar in cryptography.
Was the change discussed in an issue or in the forum before?
https://forum.rclone.org/t/whats-going-on-with-the-proposal-about-base32768-file-name-encoding/27341
https://forum.rclone.org/t/base32768-to-compress-filename-length/13202
Checklist