-
Notifications
You must be signed in to change notification settings - Fork 2
/
structures_test.go
61 lines (52 loc) · 1.83 KB
/
structures_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
56
57
58
59
60
61
// Copyright 2016 Google LLC. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package sctfe
import (
"crypto"
"crypto/x509"
"encoding/pem"
"testing"
"time"
"github.com/transparency-dev/static-ct/testdata"
)
var (
fixedTime = time.Date(2017, 9, 7, 12, 15, 23, 0, time.UTC)
fixedTimeMillis = uint64(fixedTime.UnixNano() / millisPerNano)
demoLogID = [32]byte{19, 56, 222, 93, 229, 36, 102, 128, 227, 214, 3, 121, 93, 175, 126, 236, 97, 217, 34, 32, 40, 233, 98, 27, 46, 179, 164, 251, 84, 10, 60, 57}
fakeSignature = []byte("signed")
)
func TestGetCTLogID(t *testing.T) {
block, _ := pem.Decode([]byte(testdata.DemoPublicKey))
pk, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
t.Fatalf("unexpected error loading public key: %v", err)
}
got, err := GetCTLogID(pk)
if err != nil {
t.Fatalf("error getting logid: %v", err)
}
if want := demoLogID; got != want {
t.Errorf("logID: \n%v want \n%v", got, want)
}
}
// Creates a fake signer for use in interaction tests.
// It will always return fakeSig when asked to sign something.
func setupSigner(fakeSig []byte) (crypto.Signer, error) {
block, _ := pem.Decode([]byte(testdata.DemoPublicKey))
key, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
return nil, err
}
return testdata.NewSignerWithFixedSig(key, fakeSig), nil
}