~ubuntu-branches/ubuntu/saucy/juju-core/saucy-proposed

« back to all changes in this revision

Viewing changes to src/code.google.com/p/go.crypto/ssh/cipher_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-07-11 17:18:27 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130711171827-vjqkg40r0dlf7ys2
Tags: 1.11.2-0ubuntu1
* New upstream release.
* Make juju-core the default juju (LP: #1190634):
  - d/control: Add virtual package juju -> juju-core.
  - d/juju-core.postinst.in: Bump priority of alternatives over that of
    python juju packages.
* Enable for all architectures (LP: #1172505):
  - d/control: Version BD on golang-go to >= 2:1.1.1 to ensure CGO
    support for non-x86 archs, make juju-core Arch: any.
  - d/README.source: Dropped - no longer required.
* d/watch: Updated for new upstream tarball naming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
4
 
 
5
package ssh
 
6
 
 
7
import (
 
8
        "bytes"
 
9
        "testing"
 
10
)
 
11
 
 
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")
 
18
 
 
19
        cryptBuffer := make([]byte, 32)
 
20
 
 
21
        for name, cipherMode := range cipherModes {
 
22
                encrypter, err := cipherMode.createCipher(testKey, testIv)
 
23
                if err != nil {
 
24
                        t.Errorf("failed to create encrypter for %q: %s", name, err)
 
25
                        continue
 
26
                }
 
27
                decrypter, err := cipherMode.createCipher(testKey, testIv)
 
28
                if err != nil {
 
29
                        t.Errorf("failed to create decrypter for %q: %s", name, err)
 
30
                        continue
 
31
                }
 
32
 
 
33
                copy(cryptBuffer, testData)
 
34
 
 
35
                encrypter.XORKeyStream(cryptBuffer, cryptBuffer)
 
36
                if name == "none" {
 
37
                        if !bytes.Equal(cryptBuffer, testData) {
 
38
                                t.Errorf("encryption made change with 'none' cipher")
 
39
                                continue
 
40
                        }
 
41
                } else {
 
42
                        if bytes.Equal(cryptBuffer, testData) {
 
43
                                t.Errorf("encryption made no change with %q", name)
 
44
                                continue
 
45
                        }
 
46
                }
 
47
 
 
48
                decrypter.XORKeyStream(cryptBuffer, cryptBuffer)
 
49
                if !bytes.Equal(cryptBuffer, testData) {
 
50
                        t.Errorf("decrypted bytes not equal to input with %q", name)
 
51
                        continue
 
52
                }
 
53
        }
 
54
}
 
55
 
 
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)
 
60
                }
 
61
        }
 
62
}