MCPcopy Index your code
hub / github.com/rclone/rclone / decryptFileName

Method decryptFileName

backend/crypt/cipher.go:544–585  ·  view source on GitHub ↗

decryptFileName decrypts a file path

(in string)

Source from the content-addressed store, hash-verified

542
543// decryptFileName decrypts a file path
544func (c *Cipher) decryptFileName(in string) (string, error) {
545 segments := strings.Split(in, "/")
546 for i := range segments {
547 var err error
548 // Skip directory name decryption if the user chose to
549 // leave them intact
550 if !c.dirNameEncrypt && i != (len(segments)-1) {
551 continue
552 }
553
554 // Strip version string so that only the non-versioned part
555 // of the file name gets decrypted/deobfuscated
556 hasVersion := false
557 var t time.Time
558 if i == (len(segments)-1) && version.Match(segments[i]) {
559 var s string
560 t, s = version.Remove(segments[i])
561 // version.Remove can fail, in which case it returns segments[i]
562 if s != segments[i] {
563 segments[i] = s
564 hasVersion = true
565 }
566 }
567
568 if c.mode == NameEncryptionStandard {
569 segments[i], err = c.decryptSegment(segments[i])
570 } else {
571 segments[i], err = c.deobfuscateSegment(segments[i])
572 }
573
574 if err != nil {
575 return "", err
576 }
577
578 // Add back a version to the decrypted/deobfuscated
579 // file name, if we stripped it off earlier
580 if hasVersion {
581 segments[i] = version.Add(segments[i], t)
582 }
583 }
584 return strings.Join(segments, "/"), nil
585}
586
587// DecryptFileName decrypts a file path
588func (c *Cipher) DecryptFileName(in string) (string, error) {

Callers 2

DecryptFileNameMethod · 0.95
DecryptDirNameMethod · 0.95

Calls 6

decryptSegmentMethod · 0.95
deobfuscateSegmentMethod · 0.95
MatchFunction · 0.92
RemoveFunction · 0.92
AddFunction · 0.92
JoinMethod · 0.80

Tested by

no test coverage detected