MCPcopy
hub / github.com/rclone/rclone / encryptFileName

Method encryptFileName

backend/crypt/cipher.go:489–525  ·  view source on GitHub ↗

encryptFileName encrypts a file path

(in string)

Source from the content-addressed store, hash-verified

487
488// encryptFileName encrypts a file path
489func (c *Cipher) encryptFileName(in string) string {
490 segments := strings.Split(in, "/")
491 for i := range segments {
492 // Skip directory name encryption if the user chose to
493 // leave them intact
494 if !c.dirNameEncrypt && i != (len(segments)-1) {
495 continue
496 }
497
498 // Strip version string so that only the non-versioned part
499 // of the file name gets encrypted/obfuscated
500 hasVersion := false
501 var t time.Time
502 if i == (len(segments)-1) && version.Match(segments[i]) {
503 var s string
504 t, s = version.Remove(segments[i])
505 // version.Remove can fail, in which case it returns segments[i]
506 if s != segments[i] {
507 segments[i] = s
508 hasVersion = true
509 }
510 }
511
512 if c.mode == NameEncryptionStandard {
513 segments[i] = c.encryptSegment(segments[i])
514 } else {
515 segments[i] = c.obfuscateSegment(segments[i])
516 }
517
518 // Add back a version to the encrypted/obfuscated
519 // file name, if we stripped it off earlier
520 if hasVersion {
521 segments[i] = version.Add(segments[i], t)
522 }
523 }
524 return strings.Join(segments, "/")
525}
526
527// EncryptFileName encrypts a file path
528func (c *Cipher) EncryptFileName(in string) string {

Callers 2

EncryptFileNameMethod · 0.95
EncryptDirNameMethod · 0.95

Calls 6

encryptSegmentMethod · 0.95
obfuscateSegmentMethod · 0.95
MatchFunction · 0.92
RemoveFunction · 0.92
AddFunction · 0.92
JoinMethod · 0.80

Tested by

no test coverage detected