From 966308eeb7793a4a8ca578e160981e3b059b82e6 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 5 Mar 2017 17:44:14 +0100 Subject: Drop Go 1.4 compatability code everywhere Yields a nice reduction in code size. --- build.bash | 13 +++++---- internal/cryptocore/cryptocore.go | 2 +- internal/cryptocore/cryptocore_go1.4_test.go | 20 -------------- internal/cryptocore/cryptocore_go1.5_test.go | 16 ----------- internal/cryptocore/cryptocore_test.go | 5 +++- internal/cryptocore/gcm_go1.4.go | 29 -------------------- internal/cryptocore/gcm_go1.5.go | 21 -------------- internal/nametransform/names.go | 2 +- internal/nametransform/raw64_go1.4.go | 18 ------------ internal/nametransform/raw64_go1.5.go | 16 ----------- internal/speed/speed.go | 2 -- internal/speed/speed_go1.4.go | 11 -------- internal/speed/speed_test.go | 2 -- internal/stupidgcm/stupidgcm_test.go | 4 --- internal/tlog/log.go | 25 +++++++++++++++++ internal/tlog/log_go1.4.go | 16 ----------- internal/tlog/log_go1.5.go | 32 ---------------------- .../example_filesystems_test.go | 8 +----- tests/matrix/matrix_test.go | 10 ------- 19 files changed, 39 insertions(+), 213 deletions(-) delete mode 100644 internal/cryptocore/cryptocore_go1.4_test.go delete mode 100644 internal/cryptocore/cryptocore_go1.5_test.go delete mode 100644 internal/cryptocore/gcm_go1.4.go delete mode 100644 internal/cryptocore/gcm_go1.5.go delete mode 100644 internal/nametransform/raw64_go1.4.go delete mode 100644 internal/nametransform/raw64_go1.5.go delete mode 100644 internal/speed/speed_go1.4.go delete mode 100644 internal/tlog/log_go1.4.go delete mode 100644 internal/tlog/log_go1.5.go diff --git a/build.bash b/build.bash index e492f17..1cc266b 100755 --- a/build.bash +++ b/build.bash @@ -38,16 +38,17 @@ BUILDTIME=$(date +%s) # Make sure we have the go binary go version > /dev/null -# Go 1.5 changed the CLI syntax. Let's also support 1.3 and 1.4. -# "go version go1.6.2 linux/amd64" -> "1.6" +# Parse "go version go1.6.2 linux/amd64" to "1.6" V=$(go version | cut -d" " -f3 | cut -c3-5) +# Reject old Go versions already here. It would fail with compile +# errors anyway. if [[ $V == "1.3" || $V == "1.4" ]] ; then - LDFLAGS="-X main.GitVersion $GITVERSION -X main.GitVersionFuse $GITVERSIONFUSE -X main.BuildTime $BUILDTIME" -else - # Go 1.5+ wants an "=" here - LDFLAGS="-X main.GitVersion=$GITVERSION -X main.GitVersionFuse=$GITVERSIONFUSE -X main.BuildTime=$BUILDTIME" + echo "Error: you need Go 1.5 or higher to compile gocryptfs" + echo -n "You have: " + go version fi +LDFLAGS="-X main.GitVersion=$GITVERSION -X main.GitVersionFuse=$GITVERSIONFUSE -X main.BuildTime=$BUILDTIME" go build "-ldflags=$LDFLAGS" $@ (cd gocryptfs-xray; go build $@) diff --git a/internal/cryptocore/cryptocore.go b/internal/cryptocore/cryptocore.go index fea0c94..735c409 100644 --- a/internal/cryptocore/cryptocore.go +++ b/internal/cryptocore/cryptocore.go @@ -74,7 +74,7 @@ func New(key []byte, aeadType AEADTypeEnum, IVBitLen int) *CryptoCore { } aeadCipher = stupidgcm.New(key) case BackendGoGCM: - aeadCipher, err = goGCMWrapper(blockCipher, IVLen) + aeadCipher, err = cipher.NewGCMWithNonceSize(blockCipher, IVLen) case BackendAESSIV: if IVLen != 16 { // SIV supports any nonce size, but we only use 16. diff --git a/internal/cryptocore/cryptocore_go1.4_test.go b/internal/cryptocore/cryptocore_go1.4_test.go deleted file mode 100644 index 14e1e03..0000000 --- a/internal/cryptocore/cryptocore_go1.4_test.go +++ /dev/null @@ -1,20 +0,0 @@ -// +build !go1.5 -// = go 1.4 or lower - -package cryptocore - -import ( - "testing" -) - -// Native Go crypto with 128-bit IVs is only supported on Go 1.5 and up, -// this should panic. -func TestCryptoCoreNewGo14(t *testing.T) { - defer func() { - if r := recover(); r == nil { - t.Errorf("The code did not panic") - } - }() - key := make([]byte, 32) - New(key, BackendGoGCM, 128) -} diff --git a/internal/cryptocore/cryptocore_go1.5_test.go b/internal/cryptocore/cryptocore_go1.5_test.go deleted file mode 100644 index f9d38e9..0000000 --- a/internal/cryptocore/cryptocore_go1.5_test.go +++ /dev/null @@ -1,16 +0,0 @@ -// +build go1.5 -// = go 1.5 or higher - -package cryptocore - -import ( - "testing" -) - -func TestCryptoCoreNewGo15(t *testing.T) { - key := make([]byte, 32) - c := New(key, BackendGoGCM, 128) - if c.IVLen != 16 { - t.Fail() - } -} diff --git a/internal/cryptocore/cryptocore_test.go b/internal/cryptocore/cryptocore_test.go index c54eac9..252c311 100644 --- a/internal/cryptocore/cryptocore_test.go +++ b/internal/cryptocore/cryptocore_test.go @@ -16,7 +16,10 @@ func TestCryptoCoreNew(t *testing.T) { if c.IVLen != 12 { t.Fail() } - // "New(key, BackendGoGCM, 128)" is tested for Go 1.4 and 1.5+ separately + c = New(key, BackendGoGCM, 128) + if c.IVLen != 16 { + t.Fail() + } } // "New" should panic on any key not 32 bytes long diff --git a/internal/cryptocore/gcm_go1.4.go b/internal/cryptocore/gcm_go1.4.go deleted file mode 100644 index c1aa488..0000000 --- a/internal/cryptocore/gcm_go1.4.go +++ /dev/null @@ -1,29 +0,0 @@ -// +build !go1.5 -// = go 1.4 or lower - -package cryptocore - -import ( - "crypto/cipher" - "fmt" - - "github.com/rfjakob/gocryptfs/internal/tlog" -) - -const ( - // HaveModernGoGCM indicates if Go GCM supports 128-bit nonces - HaveModernGoGCM = false -) - -// goGCMWrapper - This wrapper makes sure gocryptfs can be compiled on Go -// versions 1.4 and lower that lack NewGCMWithNonceSize(). -// 128 bit GCM IVs will not work when using built-in Go crypto, obviously, when -// compiled on 1.4. -func goGCMWrapper(bc cipher.Block, nonceSize int) (cipher.AEAD, error) { - if nonceSize != 12 { - tlog.Warn.Printf("128 bit GCM IVs are not supported by Go 1.4 and lower.") - tlog.Warn.Printf("Please use openssl crypto or recompile using a newer Go runtime.") - return nil, fmt.Errorf("128 bit GCM IVs are not supported by Go 1.4 and lower") - } - return cipher.NewGCM(bc) -} diff --git a/internal/cryptocore/gcm_go1.5.go b/internal/cryptocore/gcm_go1.5.go deleted file mode 100644 index 3c38357..0000000 --- a/internal/cryptocore/gcm_go1.5.go +++ /dev/null @@ -1,21 +0,0 @@ -// +build go1.5 -// = go 1.5 or higher - -package cryptocore - -import ( - "crypto/cipher" -) - -const ( - // HaveModernGoGCM indicates if Go GCM supports 128-bit nonces - HaveModernGoGCM = true -) - -// goGCMWrapper - This wrapper makes sure gocryptfs can be compiled on Go -// versions 1.4 and lower that lack NewGCMWithNonceSize(). -// 128 bit GCM IVs will not work when using built-in Go crypto, obviously, when -// compiled on 1.4. -func goGCMWrapper(bc cipher.Block, nonceSize int) (cipher.AEAD, error) { - return cipher.NewGCMWithNonceSize(bc, nonceSize) -} diff --git a/internal/nametransform/names.go b/internal/nametransform/names.go index feec017..83724fb 100644 --- a/internal/nametransform/names.go +++ b/internal/nametransform/names.go @@ -24,7 +24,7 @@ type NameTransform struct { func New(e *eme.EMECipher, longNames bool, raw64 bool) *NameTransform { b64 := base64.URLEncoding if raw64 { - b64 = getRaw64Encoding() + b64 = base64.RawURLEncoding } return &NameTransform{ emeCipher: e, diff --git a/internal/nametransform/raw64_go1.4.go b/internal/nametransform/raw64_go1.4.go deleted file mode 100644 index bbffb69..0000000 --- a/internal/nametransform/raw64_go1.4.go +++ /dev/null @@ -1,18 +0,0 @@ -//+build !go1.5 - -package nametransform - -import ( - "encoding/base64" - "log" -) - -const ( - HaveRaw64 = false -) - -func getRaw64Encoding() *base64.Encoding { - log.Panicf("Tried to use base64.RawURLEncoding but your Go version does not provide it.\n" + - "You need Go 1.5 or higher.") - return nil -} diff --git a/internal/nametransform/raw64_go1.5.go b/internal/nametransform/raw64_go1.5.go deleted file mode 100644 index 1896be3..0000000 --- a/internal/nametransform/raw64_go1.5.go +++ /dev/null @@ -1,16 +0,0 @@ -//+build go1.5 - -package nametransform - -import ( - "encoding/base64" -) - -const ( - // HaveRaw64 is true when Go is new enough to have base64.RawURLEncoding - HaveRaw64 = true -) - -func getRaw64Encoding() *base64.Encoding { - return base64.RawURLEncoding -} diff --git a/internal/speed/speed.go b/internal/speed/speed.go index bc829d4..f9bf93c 100644 --- a/internal/speed/speed.go +++ b/internal/speed/speed.go @@ -1,5 +1,3 @@ -// +build go1.5 - // Package speed implements the "-speed" command-line option, // similar to "openssl speed". // It benchmarks the crypto algorithms and libraries used by diff --git a/internal/speed/speed_go1.4.go b/internal/speed/speed_go1.4.go deleted file mode 100644 index 9c0125c..0000000 --- a/internal/speed/speed_go1.4.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build !go1.5 - -package speed - -import ( - "fmt" -) - -func Run() { - fmt.Printf("Compile with Go 1.5 or higher to run the benchmarks\n") -} diff --git a/internal/speed/speed_test.go b/internal/speed/speed_test.go index d6bc187..1e9d859 100644 --- a/internal/speed/speed_test.go +++ b/internal/speed/speed_test.go @@ -1,5 +1,3 @@ -// +build go1.5 - package speed /* diff --git a/internal/stupidgcm/stupidgcm_test.go b/internal/stupidgcm/stupidgcm_test.go index ba25855..3081085 100644 --- a/internal/stupidgcm/stupidgcm_test.go +++ b/internal/stupidgcm/stupidgcm_test.go @@ -1,10 +1,6 @@ -// +build go1.5 -// = go 1.5 or higher -// // We compare against Go's built-in GCM implementation. Since stupidgcm only // supports 128-bit IVs and Go only supports that from 1.5 onward, we cannot // run these tests on older Go versions. - package stupidgcm import ( diff --git a/internal/tlog/log.go b/internal/tlog/log.go index bd8844b..720bb88 100644 --- a/internal/tlog/log.go +++ b/internal/tlog/log.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "log" + "log/syslog" "os" "golang.org/x/crypto/ssh/terminal" @@ -117,3 +118,27 @@ func init() { postfix: ColorReset, } } + +// SwitchToSyslog redirects the output of this logger to syslog. +func (l *toggledLogger) SwitchToSyslog(p syslog.Priority) { + w, err := syslog.New(p, ProgramName) + if err != nil { + Warn.Printf("SwitchToSyslog: %v", err) + } else { + l.SetOutput(w) + } +} + +// SwitchLoggerToSyslog redirects the default log.Logger that the go-fuse lib uses +// to syslog. +func SwitchLoggerToSyslog(p syslog.Priority) { + w, err := syslog.New(p, ProgramName) + if err != nil { + Warn.Printf("SwitchLoggerToSyslog: %v", err) + } else { + log.SetPrefix("go-fuse: ") + // Disable printing the timestamp, syslog already provides that + log.SetFlags(0) + log.SetOutput(w) + } +} diff --git a/internal/tlog/log_go1.4.go b/internal/tlog/log_go1.4.go deleted file mode 100644 index 98d69db..0000000 --- a/internal/tlog/log_go1.4.go +++ /dev/null @@ -1,16 +0,0 @@ -// +build !go1.5 -// = go 1.4 or lower - -package tlog - -import ( - "log/syslog" -) - -func (l *toggledLogger) SwitchToSyslog(p syslog.Priority) { - Info.Printf("Cannot switch to syslog - need Go 1.5 or higher") -} - -func SwitchLoggerToSyslog(p syslog.Priority) { - Info.Printf("Cannot switch to syslog - need Go 1.5 or higher") -} diff --git a/internal/tlog/log_go1.5.go b/internal/tlog/log_go1.5.go deleted file mode 100644 index 9c152d9..0000000 --- a/internal/tlog/log_go1.5.go +++ /dev/null @@ -1,32 +0,0 @@ -// +build go1.5 -// = go 1.5 or higher - -package tlog - -import ( - "log" - "log/syslog" -) - -func (l *toggledLogger) SwitchToSyslog(p syslog.Priority) { - w, err := syslog.New(p, ProgramName) - if err != nil { - Warn.Printf("SwitchToSyslog: %v", err) - } else { - l.SetOutput(w) - } -} - -// SwitchLoggerToSyslog redirects the default log.Logger that the go-fuse lib uses -// to syslog. -func SwitchLoggerToSyslog(p syslog.Priority) { - w, err := syslog.New(p, ProgramName) - if err != nil { - Warn.Printf("SwitchLoggerToSyslog: %v", err) - } else { - log.SetPrefix("go-fuse: ") - // Disable printing the timestamp, syslog already provides that - log.SetFlags(0) - log.SetOutput(w) - } -} diff --git a/tests/example_filesystems/example_filesystems_test.go b/tests/example_filesystems/example_filesystems_test.go index 5192278..a43d2a9 100644 --- a/tests/example_filesystems/example_filesystems_test.go +++ b/tests/example_filesystems/example_filesystems_test.go @@ -12,7 +12,6 @@ import ( "os" "testing" - "github.com/rfjakob/gocryptfs/internal/cryptocore" "github.com/rfjakob/gocryptfs/internal/stupidgcm" "github.com/rfjakob/gocryptfs/tests/test_helpers" ) @@ -24,12 +23,7 @@ var opensslOpt string func TestMain(m *testing.M) { // Make "testing.Verbose()" return the correct value flag.Parse() - var variants []string - if cryptocore.HaveModernGoGCM { - variants = append(variants, "-openssl=false") - } else { - fmt.Println("Skipping Go GCM tests, Go installation is too old") - } + variants := []string{"-openssl=false"} if !stupidgcm.BuiltWithoutOpenssl { variants = append(variants, "-openssl=true") } else { diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go index 1c5d348..88c255e 100644 --- a/tests/matrix/matrix_test.go +++ b/tests/matrix/matrix_test.go @@ -23,8 +23,6 @@ import ( "syscall" "testing" - "github.com/rfjakob/gocryptfs/internal/cryptocore" - "github.com/rfjakob/gocryptfs/internal/nametransform" "github.com/rfjakob/gocryptfs/internal/syscallcompat" "github.com/rfjakob/gocryptfs/tests/test_helpers" ) @@ -60,14 +58,6 @@ func TestMain(m *testing.M) { // Make "testing.Verbose()" return the correct value flag.Parse() for _, testcase = range matrix { - if !cryptocore.HaveModernGoGCM && testcase.openssl != "true" { - fmt.Printf("Skipping Go GCM variant, Go installation is too old") - continue - } - if testcase.raw64 && !nametransform.HaveRaw64 { - fmt.Printf("Skipping raw64 test, Go installation is too old") - continue - } if testing.Verbose() { fmt.Printf("matrix: testcase = %#v\n", testcase) } -- cgit v1.2.3