Wrap NewGCMWithNonceSize() to enable compilation on Go 1.4

This commit is contained in:
Jakob Unterwurzacher 2015-12-10 20:52:59 +01:00
parent 61ee2271c4
commit 78cd97c5e9
4 changed files with 38 additions and 2 deletions

View File

@ -1,6 +1,7 @@
language: go
go:
- 1.4.3
- 1.5.1
- tip

21
cryptfs/gcm_go14.go Normal file
View File

@ -0,0 +1,21 @@
// +build !go1.5
package cryptfs
import (
"fmt"
"crypto/cipher"
)
// 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 {
Warn.Printf("128 bit GCM IVs are not supported by Go 1.4 and lower.\n")
Warn.Printf("Please use openssl crypto or recompile using a newer Go runtime.\n")
return nil, fmt.Errorf("128 bit GCM IVs are not supported by Go 1.4 and lower")
}
return cipher.NewGCM(bc)
}

15
cryptfs/gcm_go15.go Normal file
View File

@ -0,0 +1,15 @@
// +build go1.5
package cryptfs
import (
"crypto/cipher"
)
// 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)
}

View File

@ -10,7 +10,6 @@ package cryptfs
import (
"crypto/aes"
"crypto/cipher"
"testing"
)
@ -20,7 +19,7 @@ func benchmarkGoEnc(b *testing.B, plaintext []byte, key []byte, nonce []byte) (c
if err != nil {
b.Fatal(err)
}
aesgcm, err := cipher.NewGCMWithNonceSize(aes, len(nonce))
aesgcm, err := goGCMWrapper(aes, len(nonce))
if err != nil {
b.Fatal(err)
}