From 05b813f2026ebe6bff33cb600775823ee8a7df6e Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Mon, 21 Jun 2021 12:12:44 +0200 Subject: nametransform: rename BadNameFlag to BadnameSuffix --- internal/nametransform/badname.go | 18 +++++++++--------- tests/cli/cli_test.go | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/nametransform/badname.go b/internal/nametransform/badname.go index 5cc9799..44b7d36 100644 --- a/internal/nametransform/badname.go +++ b/internal/nametransform/badname.go @@ -12,9 +12,9 @@ import ( ) const ( - // BadNameFlag is appended to filenames in plaintext view if a corrupt + // BadnameSuffix is appended to filenames in plaintext view if a corrupt // ciphername is shown due to a matching `-badname` pattern - BadNameFlag = " GOCRYPTFS_BAD_NAME" + BadnameSuffix = " GOCRYPTFS_BAD_NAME" ) // EncryptAndHashBadName tries to find the "name" substring, which (encrypted and hashed) @@ -24,7 +24,7 @@ func (be *NameTransform) EncryptAndHashBadName(name string, iv []byte, dirfd int var st unix.Stat_t var filesFound int lastFoundName, err := be.EncryptAndHashName(name, iv) - if !strings.HasSuffix(name, BadNameFlag) || err != nil { + if !strings.HasSuffix(name, BadnameSuffix) || err != nil { //Default mode: same behaviour on error or no BadNameFlag on "name" return lastFoundName, err } @@ -35,13 +35,13 @@ func (be *NameTransform) EncryptAndHashBadName(name string, iv []byte, dirfd int return lastFoundName, nil } //BadName Mode: check if the name was tranformed without change (badname suffix and undecryptable cipher name) - err = syscallcompat.Fstatat(dirfd, name[:len(name)-len(BadNameFlag)], &st, unix.AT_SYMLINK_NOFOLLOW) + err = syscallcompat.Fstatat(dirfd, name[:len(name)-len(BadnameSuffix)], &st, unix.AT_SYMLINK_NOFOLLOW) if err == nil { filesFound++ - lastFoundName = name[:len(name)-len(BadNameFlag)] + lastFoundName = name[:len(name)-len(BadnameSuffix)] } // search for the longest badname pattern match - for charpos := len(name) - len(BadNameFlag); charpos > 0; charpos-- { + for charpos := len(name) - len(BadnameSuffix); charpos > 0; charpos-- { //only use original cipher name and append assumed suffix (without badname flag) cNamePart, err := be.EncryptName(name[:charpos], iv) if err != nil { @@ -51,7 +51,7 @@ func (be *NameTransform) EncryptAndHashBadName(name string, iv []byte, dirfd int if be.longNames && len(cName) > NameMax { cNamePart = be.HashLongName(cName) } - cNameBadReverse := cNamePart + name[charpos:len(name)-len(BadNameFlag)] + cNameBadReverse := cNamePart + name[charpos:len(name)-len(BadnameSuffix)] err = syscallcompat.Fstatat(dirfd, cNameBadReverse, &st, unix.AT_SYMLINK_NOFOLLOW) if err == nil { filesFound++ @@ -76,10 +76,10 @@ func (n *NameTransform) decryptBadname(cipherName string, iv []byte) (string, er for charpos := len(cipherName) - 1; charpos >= nameMin; charpos-- { res, err := n.decryptName(cipherName[:charpos], iv) if err == nil { - return res + cipherName[charpos:] + BadNameFlag, nil + return res + cipherName[charpos:] + BadnameSuffix, nil } } - return cipherName + BadNameFlag, nil + return cipherName + BadnameSuffix, nil } } return "", syscall.EBADMSG diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go index 08c1b83..df36822 100644 --- a/tests/cli/cli_test.go +++ b/tests/cli/cli_test.go @@ -764,7 +764,7 @@ func TestBadname(t *testing.T) { } // Case 2: File with invalid suffix in plain name but valid cipher file - file = mnt + "/" + validFileName + nametransform.BadNameFlag + file = mnt + "/" + validFileName + nametransform.BadnameSuffix err = ioutil.WriteFile(file, []byte("Content Case 2."), 0600) if err != nil { t.Fatal(err) @@ -819,12 +819,12 @@ func TestBadname(t *testing.T) { searchstrings := []string{ validFileName, - validFileName + nametransform.BadNameFlag, + validFileName + nametransform.BadnameSuffix, "", - validFileName + invalidSuffix + nametransform.BadNameFlag, - encryptedfilename[:len(encryptedfilename)-2] + invalidSuffix + nametransform.BadNameFlag, + validFileName + invalidSuffix + nametransform.BadnameSuffix, + encryptedfilename[:len(encryptedfilename)-2] + invalidSuffix + nametransform.BadnameSuffix, "", - validFileName + "wrongPattern" + nametransform.BadNameFlag} + validFileName + "wrongPattern" + nametransform.BadnameSuffix} results := []bool{false, false, true, false, false, true, true} var filecontent string var filebytes []byte -- cgit v1.2.3