1
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
12
// TestCipherReversal tests that each cipher factory produces ciphers that can
13
// encrypt and decrypt some data successfully.
14
func TestCipherReversal(t *testing.T) {
15
testData := []byte("abcdefghijklmnopqrstuvwxyz012345")
16
testKey := []byte("AbCdEfGhIjKlMnOpQrStUvWxYz012345")
17
testIv := []byte("sdflkjhsadflkjhasdflkjhsadfklhsa")
19
cryptBuffer := make([]byte, 32)
21
for name, cipherMode := range cipherModes {
22
encrypter, err := cipherMode.createCipher(testKey, testIv)
24
t.Errorf("failed to create encrypter for %q: %s", name, err)
27
decrypter, err := cipherMode.createCipher(testKey, testIv)
29
t.Errorf("failed to create decrypter for %q: %s", name, err)
33
copy(cryptBuffer, testData)
35
encrypter.XORKeyStream(cryptBuffer, cryptBuffer)
37
if !bytes.Equal(cryptBuffer, testData) {
38
t.Errorf("encryption made change with 'none' cipher")
42
if bytes.Equal(cryptBuffer, testData) {
43
t.Errorf("encryption made no change with %q", name)
48
decrypter.XORKeyStream(cryptBuffer, cryptBuffer)
49
if !bytes.Equal(cryptBuffer, testData) {
50
t.Errorf("decrypted bytes not equal to input with %q", name)
56
func TestDefaultCiphersExist(t *testing.T) {
57
for _, cipherAlgo := range DefaultCipherOrder {
58
if _, ok := cipherModes[cipherAlgo]; !ok {
59
t.Errorf("default cipher %q is unknown", cipherAlgo)