fixed crypto

This commit is contained in:
Jae Kwon
2014-05-26 04:11:47 -07:00
parent e9e130b4ad
commit 55a9031e91
2 changed files with 44 additions and 9 deletions

35
crypto/ed25519_test.go Normal file
View File

@ -0,0 +1,35 @@
package crypto
import (
"testing"
"crypto/rand"
)
func TestSign(t *testing.T) {
privKey := make([]byte, 32)
_, err := rand.Read(privKey)
if err != nil { t.Fatal(err) }
pubKey := MakePubKey(privKey)
signature := SignMessage([]byte("hello"), privKey, pubKey)
v1 := &Verify{
Message: []byte("hello"),
PubKey: pubKey,
Signature: signature,
}
ok := VerifyBatch([]*Verify{v1, v1, v1, v1})
if ok != true { t.Fatal("Expected ok == true") }
if v1.Valid != true { t.Fatal("Expected v1.Valid to be true") }
v2 := &Verify{
Message: []byte{0x73},
PubKey: pubKey,
Signature: signature,
}
ok = VerifyBatch([]*Verify{v1, v1, v1, v2})
if ok != false { t.Fatal("Expected ok == false") }
if v1.Valid != true { t.Fatal("Expected v1.Valid to be true") }
if v2.Valid != false { t.Fatal("Expected v2.Valid to be true") }
}