File: random_test.go

package info (click to toggle)
golang-github-twstrike-otr3 0.0~git20161015.0.744856d-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,080 kB
  • sloc: ansic: 127; makefile: 76
file content (33 lines) | stat: -rw-r--r-- 770 bytes parent folder | download | duplicates (3)
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)
}