diff options
author | Russ Cox <rsc@golang.org> | 2009-06-25 20:24:55 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-06-25 20:24:55 -0700 |
commit | b26cd1bfcd7107d8208595614ba45f54d5efacf6 (patch) | |
tree | 1596fd2f89c1d896cdf5772aebc910f4e0ff5bda /src/pkg/crypto/aes | |
parent | 37fd11a43607dc5f7ff5c38311b060ada2a0e7a5 (diff) | |
download | golang-b26cd1bfcd7107d8208595614ba45f54d5efacf6.tar.gz |
Change os.Error convention:
echo back context of call in error if likely to be useful.
For example, if os.Open("/etc/passwd", os.O_RDONLY)
fails with syscall.EPERM, it returns as the os.Error
&PathError{
Op: "open",
Path: "/etc/passwd"
Error: os.EPERM
}
which formats as
open /etc/passwd: permission denied
Not converted:
datafmt
go/...
google/...
regexp
tabwriter
template
R=r
DELTA=1153 (561 added, 156 deleted, 436 changed)
OCL=30738
CL=30781
Diffstat (limited to 'src/pkg/crypto/aes')
-rw-r--r-- | src/pkg/crypto/aes/cipher.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/pkg/crypto/aes/cipher.go b/src/pkg/crypto/aes/cipher.go index fd8e43e16..e430c9e14 100644 --- a/src/pkg/crypto/aes/cipher.go +++ b/src/pkg/crypto/aes/cipher.go @@ -7,6 +7,7 @@ package aes import ( "crypto/aes"; "os"; + "strconv"; ) // The AES block size in bytes. @@ -18,19 +19,25 @@ type Cipher struct { dec []uint32; } +type KeySizeError int +func (k KeySizeError) String() string { + return "crypto/aes: invalid key size " + strconv.Itoa(int(k)); +} + // NewCipher creates and returns a new Cipher. // The key argument should be the AES key, // either 16, 24, or 32 bytes to select // AES-128, AES-192, or AES-256. func NewCipher(key []byte) (*Cipher, os.Error) { - switch len(key) { + k := len(key); + switch k { default: - return nil, os.ErrorString("crypto/aes: invalid key size"); + return nil, KeySizeError(k); case 16, 24, 32: break; } - n := len(key) + 28; + n := k + 28; c := &Cipher{make([]uint32, n), make([]uint32, n)}; expandKey(key, c.enc, c.dec); return c, nil; |