From ac1221395e7475fa16f8f21f5badd93e300cb9d0 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Fri, 2 Sep 2016 23:39:50 +0200 Subject: [PATCH] nametransform: export DirIVLen constant Will be needed by reverse mode. --- internal/nametransform/diriv.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/nametransform/diriv.go b/internal/nametransform/diriv.go index 51af1c3..11bd729 100644 --- a/internal/nametransform/diriv.go +++ b/internal/nametransform/diriv.go @@ -15,7 +15,7 @@ import ( const ( // identical to AES block size - dirIVLen = 16 + DirIVLen = 16 // dirIV is stored in this file. Exported because we have to ignore this // name in directory listing. DirIVFilename = "gocryptfs.diriv" @@ -45,15 +45,17 @@ func ReadDirIVAt(dirfd *os.File) (iv []byte, err error) { fd := os.NewFile(uintptr(fdRaw), DirIVFilename) defer fd.Close() - iv = make([]byte, dirIVLen+1) + // We want to detect if the file is bigger than DirIVLen, so + // make the buffer 1 byte bigger than neccessary. + iv = make([]byte, DirIVLen+1) n, err := fd.Read(iv) if err != nil { tlog.Warn.Printf("ReadDirIVAt: Read failed: %v", err) return nil, err } iv = iv[0:n] - if len(iv) != dirIVLen { - tlog.Warn.Printf("ReadDirIVAt: wanted %d bytes, got %d", dirIVLen, len(iv)) + if len(iv) != DirIVLen { + tlog.Warn.Printf("ReadDirIVAt: wanted %d bytes, got %d", DirIVLen, len(iv)) return nil, errors.New("invalid iv length") } return iv, nil @@ -63,7 +65,7 @@ func ReadDirIVAt(dirfd *os.File) (iv []byte, err error) { // This function is exported because it is used from pathfs_frontend, main, // and also the automated tests. func WriteDirIV(dir string) error { - iv := cryptocore.RandBytes(dirIVLen) + iv := cryptocore.RandBytes(DirIVLen) file := filepath.Join(dir, DirIVFilename) err := ioutil.WriteFile(file, iv, 0400) if err != nil {