-
Notifications
You must be signed in to change notification settings - Fork 11
/
eventdata_test.go
55 lines (40 loc) · 1.43 KB
/
eventdata_test.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2021 Canonical Ltd.
// Licensed under the LGPLv3 with static-linking exception.
// See LICENCE file for details.
package tcglog_test
import (
"bytes"
"crypto"
_ "crypto/sha1"
_ "crypto/sha256"
. "gopkg.in/check.v1"
. "github.com/canonical/tcglog-parser"
)
type eventdataSuite struct{}
var _ = Suite(&eventdataSuite{})
func (s *eventdataSuite) TestOpaqueEventDataWrite1(c *C) {
w := new(bytes.Buffer)
d := OpaqueEventData("foo")
c.Check(d.Write(w), IsNil)
c.Check(w.Bytes(), DeepEquals, []byte(d))
}
func (s *eventdataSuite) TestOpaqueEventDataWrite2(c *C) {
w := new(bytes.Buffer)
d := OpaqueEventData("bar")
c.Check(d.Write(w), IsNil)
c.Check(w.Bytes(), DeepEquals, []byte(d))
}
func (s *eventdataSuite) TestOpaqueEventDataString(c *C) {
event := OpaqueEventData([]byte{1, 2, 3, 4})
c.Check(event.String(), Equals, "")
event = OpaqueEventData([]byte("foo"))
c.Check(event.String(), Equals, "foo")
event = OpaqueEventData([]byte("bar\x00"))
c.Check(event.String(), Equals, "bar")
event = OpaqueEventData([]byte("fo\x7fo"))
c.Check(event.String(), Equals, "")
}
func (s *eventdataSuite) TestComputeEventDigest(c *C) {
c.Check(ComputeEventDigest(crypto.SHA256, []byte("foo")), DeepEquals, decodeHexString(c, "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"))
c.Check(ComputeEventDigest(crypto.SHA1, []byte("bar")), DeepEquals, decodeHexString(c, "62cdb7020ff920e5aa642c3d4066950dd1f01f4d"))
}