Skip to content

Commit

Permalink
Store cipherInfo pointer in cipherMethod map.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed May 29, 2013
1 parent 5cf244d commit db2a450
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions shadowsocks/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ func newRC4Cipher(key []byte) (enc, dec cipher.Stream, err error) {
return rc4Enc, &rc4Dec, nil
}

type cipherInfo struct {
keyLen int
ivLen int
newBlock func([]byte) (cipher.Block, error)
}

// Ciphers from go.crypto has NewCipher returning specific type of cipher
// instead of cipher.Block, so we need to have the following adapter
// functions.
Expand All @@ -109,7 +103,13 @@ func newCast5Cipher(key []byte) (cipher.Block, error) {
return cast5.NewCipher(key)
}

var cipherMethod = map[string]cipherInfo{
type cipherInfo struct {
keyLen int
ivLen int
newBlock func([]byte) (cipher.Block, error)
}

var cipherMethod = map[string]*cipherInfo{
"aes-128-cfb": {16, 16, aes.NewCipher},
"aes-192-cfb": {24, 16, aes.NewCipher},
"aes-256-cfb": {32, 16, aes.NewCipher},
Expand Down Expand Up @@ -149,7 +149,7 @@ func NewCipher(method, password string) (c *Cipher, err error) {

key := evpBytesToKey(password, mi.keyLen)

c = &Cipher{key: key, info: &mi}
c = &Cipher{key: key, info: mi}

if mi.newBlock == nil {
if method == "" {
Expand Down

0 comments on commit db2a450

Please sign in to comment.