Skip to content

Commit

Permalink
Fix test.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Feb 28, 2013
1 parent 029685b commit eb62155
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions shadowsocks/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"errors"
)

var errEmptyKey = errors.New("empty key")

type Cipher interface {
// Some ciphers maintains context (e.g. RC4), which means different
// connections need to use their own ciphers. Copy() will create an copy
Expand All @@ -27,6 +29,9 @@ type TableCipher struct {

// Creates a new table based cipher. err is always nil.
func NewTableCipher(key string) (c Cipher, err error) {
if key == "" {
return nil, errEmptyKey
}
const tbl_size = 256
tbl := TableCipher{
make([]byte, tbl_size),
Expand Down Expand Up @@ -83,6 +88,9 @@ type RC4Cipher struct {
}

func NewRC4Cipher(key string) (c Cipher, err error) {
if key == "" {
return nil, errEmptyKey
}
h := md5.New()
h.Write([]byte(key))
enc, err := rc4.NewCipher(h.Sum(nil))
Expand Down

0 comments on commit eb62155

Please sign in to comment.