Skip to content

Commit

Permalink
feat(crypt): customize filename_encoding (#5148)
Browse files Browse the repository at this point in the history
close #5109
close #5080
  • Loading branch information
SeanHeuc authored Sep 3, 2023
1 parent e7c0d94 commit 37dffd0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 3 additions & 1 deletion drivers/crypt/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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": "",
}
Expand Down
13 changes: 4 additions & 9 deletions drivers/crypt/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions pkg/utils/str.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}

0 comments on commit 37dffd0

Please sign in to comment.