diff --git a/drivers/crypt/driver.go b/drivers/crypt/driver.go index cf33c357f83..221ee8cb4b2 100644 --- a/drivers/crypt/driver.go +++ b/drivers/crypt/driver.go @@ -54,6 +54,8 @@ func (d *Crypt) Init(ctx context.Context) error { if !isCryptExt(d.EncryptedSuffix) { return fmt.Errorf("EncryptedSuffix is Illegal") } + d.FileNameEncoding = utils.GetNoneEmpty(d.FileNameEncoding, "base64") + d.EncryptedSuffix = utils.GetNoneEmpty(d.EncryptedSuffix, ".bin") op.MustSaveDriverStorage(d) @@ -71,7 +73,7 @@ func (d *Crypt) Init(ctx context.Context) error { "password2": p2, "filename_encryption": d.FileNameEnc, "directory_name_encryption": d.DirNameEnc, - "filename_encoding": "base64", + "filename_encoding": d.FileNameEncoding, "suffix": d.EncryptedSuffix, "pass_bad_blocks": "", } diff --git a/drivers/crypt/meta.go b/drivers/crypt/meta.go index 68eab6b430b..76dd2bcb235 100644 --- a/drivers/crypt/meta.go +++ b/drivers/crypt/meta.go @@ -15,17 +15,12 @@ type Addition struct { DirNameEnc string `json:"directory_name_encryption" type:"select" required:"true" options:"false,true" default:"false"` RemotePath string `json:"remote_path" required:"true" help:"This is where the encrypted data stores"` - Password string `json:"password" required:"true" confidential:"true" help:"the main password"` - Salt string `json:"salt" confidential:"true" help:"If you don't know what is salt, treat it as a second password'. Optional but recommended"` - EncryptedSuffix string `json:"encrypted_suffix" required:"true" default:".bin" help:"encrypted files will have this suffix"` + Password string `json:"password" required:"true" confidential:"true" help:"the main password"` + Salt string `json:"salt" confidential:"true" help:"If you don't know what is salt, treat it as a second password. Optional but recommended"` + EncryptedSuffix string `json:"encrypted_suffix" required:"true" default:".bin" help:"for advanced user only! encrypted files will have this suffix"` + FileNameEncoding string `json:"filename_encoding" type:"select" required:"true" options:"base64,base32,base32768" default:"base64" help:"for advanced user only!"` } -/*// inMemory contains decrypted confidential info and other temp data. will not persist these info anywhere -type inMemory struct { - password string - salt string -}*/ - var config = driver.Config{ Name: "Crypt", LocalSort: true, diff --git a/pkg/utils/str.go b/pkg/utils/str.go index 509bb82809c..e42484dc78b 100644 --- a/pkg/utils/str.go +++ b/pkg/utils/str.go @@ -30,3 +30,13 @@ func SafeAtob(data string) (string, error) { } return string(bytes), err } + +// GetNoneEmpty returns the first non-empty string, return empty if all empty +func GetNoneEmpty(strArr ...string) string { + for _, s := range strArr { + if len(s) > 0 { + return s + } + } + return "" +}