"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
cryptdecode: added option to return encrypted file names. Fixes #1923
ishuah0a7731cf0d49
diff --git a/cmd/cryptdecode/cryptdecode.go b/cmd/cryptdecode/cryptdecode.goindex c1c130857..fe46dd10f 100644--- a/cmd/cryptdecode/cryptdecode.go+++ b/cmd/cryptdecode/cryptdecode.go@@ -10,8 +10,15 @@ import ("github.com/spf13/cobra")+// Options set by command line flags+var (+ Reverse = false+)+func init() {cmd.Root.AddCommand(commandDefinition)+ flags := commandDefinition.Flags()+ fs.BoolVarP(flags, &Reverse, "reverse", "", Reverse, "Reverse cryptdecode, encrypts filenames")}var commandDefinition = &cobra.Command{@@ -21,25 +28,44 @@ var commandDefinition = &cobra.Command{rclone cryptdecode returns unencrypted file names when provided witha list of encrypted file names. List limit is 10 items.+If you supply the --reverse flag, it will return encrypted file names.+use it like thisrclone cryptdecode encryptedremote: encryptedfilename1 encryptedfilename2++ rclone cryptdecode --reverse encryptedremote: filename1 filename2`,Run: func(command *cobra.Command, args []string) {cmd.CheckArgs(2, 11, command, args)fsrc := cmd.NewFsSrc(args)- cmd.Run(false, false, command, func() error {- return cryptDecode(fsrc, args[1:])- })+ if Reverse {+ cmd.Run(false, false, command, func() error {+ return cryptEncode(fsrc, args[1:])+ })+ } else {+ cmd.Run(false, false, command, func() error {+ return cryptDecode(fsrc, args[1:])+ })+ }},}-// cryptDecode returns the unencrypted file name-func cryptDecode(fsrc fs.Fs, args []string) error {- // Check if fsrc is a crypt+// Check if fsrc is a crypt+func assertCryptFs(fsrc fs.Fs) (*crypt.Fs, error) {fcrypt, ok := fsrc.(*crypt.Fs)if !ok {- return errors.Errorf("%s:%s is not a crypt remote", fsrc.Name(), fsrc.Root())+ return nil, errors.Errorf("%s:%s is not a crypt remote", fsrc.Name(), fsrc.Root())+ }+ return fcrypt, nil+}++// cryptDecode returns the unencrypted file name+func cryptDecode(fsrc fs.Fs, args []string) error {+ fcrypt, err := assertCryptFs(fsrc)++ if err != nil {+ return err}output := ""@@ -57,3 +83,23 @@ func cryptDecode(fsrc fs.Fs, args []string) error {return nil}++// cryptEncode returns the encrypted file name+func cryptEncode(fsrc fs.Fs, args []string) error {+ fcrypt, err := assertCryptFs(fsrc)++ if err != nil {+ return err+ }++ output := ""++ for _, fileName := range args {+ encryptedFileName := fcrypt.EncryptFileName(fileName)+ output += fmt.Sprintln(fileName, "\t", encryptedFileName)+ }++ fmt.Printf(output)++ return nil+}diff --git a/crypt/crypt.go b/crypt/crypt.goindex dcd69798c..911454524 100644--- a/crypt/crypt.go+++ b/crypt/crypt.go@@ -445,6 +445,11 @@ func (f *Fs) UnWrap() fs.Fs {return f.Fs}+// EncryptFileName returns an encrypted file name+func (f *Fs) EncryptFileName(fileName string) string {+ return f.cipher.EncryptFileName(fileName)+}+// DecryptFileName returns a decrypted file namefunc (f *Fs) DecryptFileName(encryptedFileName string) (string, error) {return f.cipher.DecryptFileName(encryptedFileName)