1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-30 18:13:54 +08:00

Updated tests.

This commit is contained in:
Brendan Mc
2014-09-03 21:28:11 -04:00
parent ca8b7d48e0
commit 0e185788fc
2 changed files with 10 additions and 11 deletions

View File

@ -4,8 +4,6 @@ package identify
import ( import (
"bytes" "bytes"
"errors"
"crypto/aes" "crypto/aes"
"crypto/cipher" "crypto/cipher"
"crypto/elliptic" "crypto/elliptic"
@ -14,6 +12,7 @@ import (
"crypto/sha1" "crypto/sha1"
"crypto/sha256" "crypto/sha256"
"crypto/sha512" "crypto/sha512"
"errors"
"hash" "hash"
"math/big" "math/big"
"strings" "strings"
@ -86,12 +85,12 @@ func Handshake(self, remote *peer.Peer, in, out chan []byte) (chan []byte, chan
return nil, nil, err return nil, nil, err
} }
cipherType, err := selectBest(SupportedExchanges, helloResp.GetCiphers()) cipherType, err := selectBest(SupportedCiphers, helloResp.GetCiphers())
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
hashType, err := selectBest(SupportedExchanges, helloResp.GetHashes()) hashType, err := selectBest(SupportedHashes, helloResp.GetHashes())
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -249,10 +248,10 @@ func IdFromPubKey(pk ci.PubKey) (peer.ID, error) {
func keyGenerator(cmp int, cipherType string, hashType string, secret []byte) ([]byte, []byte, []byte, []byte, []byte, []byte) { func keyGenerator(cmp int, cipherType string, hashType string, secret []byte) ([]byte, []byte, []byte, []byte, []byte, []byte) {
var cipherKeySize int var cipherKeySize int
switch cipherType { switch cipherType {
case "AES128": case "AES-128":
cipherKeySize = 2 * 16 cipherKeySize = 16
case "AES256": case "AES-256":
cipherKeySize = 2 * 32 cipherKeySize = 32
} }
ivSize := 16 ivSize := 16
@ -387,7 +386,7 @@ func generateEPubKey(exchange string) ([]byte, func([]byte) ([]byte, error), err
// Verify and unpack node's public key. // Verify and unpack node's public key.
curveSize := curve.Params().BitSize curveSize := curve.Params().BitSize
if len(theirPub) != (curveSize / 2) { if len(theirPub) != (curveSize / 4) {
return nil, errors.New("Malformed public key.") return nil, errors.New("Malformed public key.")
} }

View File

@ -41,13 +41,13 @@ func TestHandshake(t *testing.T) {
} }
go func() { go func() {
err := Handshake(pa, pb, cha, chb) _, _, err := Handshake(pa, pb, cha, chb)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
}() }()
err = Handshake(pb, pa, chb, cha) _, _, err = Handshake(pb, pa, chb, cha)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }