noise/box/box_test.go
Jonathan Rudenberg 63cdf72db2
Somehow this works
2014-07-02 23:49:15 -07:00

46 lines
949 B
Go

package box
import (
"crypto/rand"
"testing"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
type S struct{}
var _ = Suite(&S{})
func (s *S) TestRoundtrip(c *C) {
recvKey, _ := Noise255.GenerateKey(rand.Reader)
sendKey, _ := Noise255.GenerateKey(rand.Reader)
enc := &Crypter{
Cipher: Noise255,
SenderKey: sendKey,
ReceiverKey: recvKey,
}
enc.ReceiverKey.Private = nil
dec := &Crypter{
Cipher: Noise255,
SenderKey: sendKey,
ReceiverKey: recvKey,
}
dec.SenderKey.Private = nil
plain := []byte("yellow submarines")
padLen := 2
ciphertext, err := enc.Encrypt(nil, nil, plain, padLen)
c.Assert(err, IsNil)
expectedLen := len(plain) + padLen + (2 * Noise255.DHLen()) + (2 * Noise255.MACLen()) + 4
c.Assert(ciphertext, HasLen, expectedLen, Commentf("expected: %d", expectedLen))
plaintext, err := dec.Decrypt(ciphertext)
c.Assert(err, IsNil)
c.Assert(plaintext, DeepEquals, plain)
}