Skip to content

Commit

Permalink
Minor changes about errors
Browse files Browse the repository at this point in the history
  • Loading branch information
riobard committed Feb 5, 2017
1 parent dd52fbd commit c8b84e0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cipher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"crypto/cipher"
"crypto/md5"
"fmt"
"errors"
"net"
"sort"
"strings"
Expand All @@ -14,6 +14,8 @@ import (
"github.com/riobard/go-shadowsocks2/shadowstream"
)

var errCipherNotSupported = errors.New("ciper not supported")

// List of AEAD ciphers: key size in bytes and constructor
var aeadList = map[string]struct {
KeySize int
Expand Down Expand Up @@ -68,7 +70,7 @@ func pickCipher(name string, key []byte, password string) (core.StreamConnCipher
key = kdf(password, choice.KeySize)
}
if len(key) != choice.KeySize {
return nil, nil, fmt.Errorf("key size error: need %d-byte key", choice.KeySize)
return nil, nil, sscipher.KeySizeError(choice.KeySize)
}
aead, err := choice.New(key)
return aeadStream(aead), aeadPacket(aead), err
Expand All @@ -79,13 +81,13 @@ func pickCipher(name string, key []byte, password string) (core.StreamConnCipher
key = kdf(password, choice.KeySize)
}
if len(key) != choice.KeySize {
return nil, nil, fmt.Errorf("key size error: need %d-byte key", choice.KeySize)
return nil, nil, sscipher.KeySizeError(choice.KeySize)
}
ciph, err := choice.New(key)
return streamStream(ciph), streamPacket(ciph), err
}

return nil, nil, fmt.Errorf("cipher %q not supported", name)
return nil, nil, errCipherNotSupported
}

func aeadStream(aead cipher.AEAD) core.StreamConnCipher {
Expand Down

0 comments on commit c8b84e0

Please sign in to comment.