Exemple #1
0
func (t *SignerTest) TestSigner(c *C) {
	s := signer.NewSigner(h)

	table := []struct {
		data    []byte
		message []byte
	}{
		{
			data:    []byte{0x68, 0x65, 0x6c, 0x6c, 0x6f},
			message: []byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0xd3, 0xa4, 0x8a, 0x32, 0x96, 0xa6, 0x30, 0x27, 0x3e, 0x1b, 0x38, 0xf6, 0x78, 0x7b, 0x97, 0xa9, 0x53, 0x8c, 0xc5, 0xf9},
		},
		{
			data:    nil,
			message: []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9b, 0x66, 0x7, 0x54, 0x9d, 0x15, 0xcc, 0x3b, 0x82, 0xda, 0x27, 0x8e, 0x6c, 0xf1, 0x8e, 0xcf, 0xc2, 0x9e, 0x9d, 0x8d},
		},
	}
	for _, r := range table {
		for i := 0; i < 10; i++ {
			c.Assert(s.Sign(r.data), DeepEquals, r.message)
			data, ok := s.Verify(r.message)
			c.Assert(data, HasLen, len(r.data))
			if len(data) > 0 {
				c.Assert(data, DeepEquals, r.data)
			}
			c.Assert(ok, Equals, true)
		}
	}
}
Exemple #2
0
func (t *SignerTest) BenchmarkVerify(c *C) {
	s := signer.NewSigner(h)
	msg := []byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x85, 0xc5, 0xc2, 0xd, 0x33, 0xc0, 0x28, 0xd7, 0xda, 0x70, 0xdc, 0x85, 0x37, 0x3f, 0xe7, 0x40}

	for i := 0; i < c.N; i++ {
		s.Verify(msg)
	}
}
Exemple #3
0
func (t *SignerTest) BenchmarkSign(c *C) {
	s := signer.NewSigner(h)
	data := []byte("hello")

	for i := 0; i < c.N; i++ {
		s.Sign(data)
	}
}
Exemple #4
0
func (t *SignerTest) TestVerify(c *C) {
	s := signer.NewSigner(h)

	table := [][]byte{
		nil,
		[]byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
		[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
		[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
	}
	for _, msg := range table {
		for i := 0; i < 10; i++ {
			data, ok := s.Verify(msg)
			c.Assert(data, IsNil)
			c.Assert(ok, Equals, false)
		}
	}
}