1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
package otr3
import (
"crypto/rand"
"testing"
)
func Test_conversation_rand_returnsTheSetRandomIfThereIsOne(t *testing.T) {
r := fixtureRand()
c := &Conversation{Rand: r}
assertEquals(t, c.rand(), r)
}
func Test_conversation_rand_returnsRandReaderIfNoRandomnessIsSet(t *testing.T) {
c := &Conversation{}
assertEquals(t, c.rand(), rand.Reader)
}
func Test_randMPI_returnsNilForARealRead(t *testing.T) {
c := newConversation(otrV3{}, fixedRand([]string{"ABCD"}))
var buf [2]byte
_, err := c.randMPI(buf[:])
assertEquals(t, err, nil)
}
func Test_randMPI_returnsShortRandomReadErrorIfFails(t *testing.T) {
c := newConversation(otrV3{}, fixedRand([]string{"ABCD"}))
var buf [3]byte
_, err := c.randMPI(buf[:])
assertEquals(t, err, errShortRandomRead)
}
|