~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/crypto/cipher/cipher_test.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 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 cipher_test
 
6
 
 
7
import (
 
8
        "crypto/aes"
 
9
        "crypto/cipher"
 
10
        "testing"
 
11
)
 
12
 
 
13
func TestCryptBlocks(t *testing.T) {
 
14
        buf := make([]byte, 16)
 
15
        block, _ := aes.NewCipher(buf)
 
16
 
 
17
        mode := cipher.NewCBCDecrypter(block, buf)
 
18
        mustPanic(t, "crypto/cipher: input not full blocks", func() { mode.CryptBlocks(buf, buf[:3]) })
 
19
        mustPanic(t, "crypto/cipher: output smaller than input", func() { mode.CryptBlocks(buf[:3], buf) })
 
20
 
 
21
        mode = cipher.NewCBCEncrypter(block, buf)
 
22
        mustPanic(t, "crypto/cipher: input not full blocks", func() { mode.CryptBlocks(buf, buf[:3]) })
 
23
        mustPanic(t, "crypto/cipher: output smaller than input", func() { mode.CryptBlocks(buf[:3], buf) })
 
24
}
 
25
 
 
26
func mustPanic(t *testing.T, msg string, f func()) {
 
27
        defer func() {
 
28
                err := recover()
 
29
                if err == nil {
 
30
                        t.Errorf("function did not panic, wanted %q", msg)
 
31
                } else if err != msg {
 
32
                        t.Errorf("got panic %v, wanted %q", err, msg)
 
33
                }
 
34
        }()
 
35
        f()
 
36
}