diff options
author | Jakob Unterwurzacher | 2016-11-01 19:20:55 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2016-11-01 19:25:59 +0100 |
commit | d15122d3d6b67d42617ed9950ce5273d0dba64fd (patch) | |
tree | cf8928a9335ec7b1fea3e03fd8a32042a8485189 | |
parent | f4c367381ea4884a9b460e073a7809665031a88c (diff) |
Add Go 1.4 compatibility layer for raw64
Using raw64 will not work, but at least it will compile.
-rw-r--r-- | internal/nametransform/names.go | 2 | ||||
-rw-r--r-- | internal/nametransform/raw64_go1.4.go | 18 | ||||
-rw-r--r-- | internal/nametransform/raw64_go1.5.go | 15 | ||||
-rw-r--r-- | tests/matrix/matrix_test.go | 5 |
4 files changed, 39 insertions, 1 deletions
diff --git a/internal/nametransform/names.go b/internal/nametransform/names.go index 9b1639f..ddb5faa 100644 --- a/internal/nametransform/names.go +++ b/internal/nametransform/names.go @@ -25,7 +25,7 @@ type NameTransform struct { func New(c *cryptocore.CryptoCore, longNames bool, raw64 bool) *NameTransform { b64 := base64.URLEncoding if raw64 { - b64 = base64.RawURLEncoding + b64 = getRaw64Encoding() } return &NameTransform{ cryptoCore: c, diff --git a/internal/nametransform/raw64_go1.4.go b/internal/nametransform/raw64_go1.4.go new file mode 100644 index 0000000..bbffb69 --- /dev/null +++ b/internal/nametransform/raw64_go1.4.go @@ -0,0 +1,18 @@ +//+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 new file mode 100644 index 0000000..aa7f7fd --- /dev/null +++ b/internal/nametransform/raw64_go1.5.go @@ -0,0 +1,15 @@ +//+build go1.5 + +package nametransform + +import ( + "encoding/base64" +) + +const ( + HaveRaw64 = true +) + +func getRaw64Encoding() *base64.Encoding { + return base64.RawURLEncoding +} diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go index e1bb243..55f3947 100644 --- a/tests/matrix/matrix_test.go +++ b/tests/matrix/matrix_test.go @@ -24,6 +24,7 @@ import ( "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" ) @@ -63,6 +64,10 @@ func TestMain(m *testing.M) { 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) } |