...

Source file src/github.com/google/certificate-transparency-go/trillian/ctfe/structures_test.go

Documentation: github.com/google/certificate-transparency-go/trillian/ctfe

     1  // Copyright 2016 Google LLC. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package ctfe
    16  
    17  import (
    18  	"crypto"
    19  	"crypto/x509"
    20  	"encoding/pem"
    21  	"testing"
    22  	"time"
    23  
    24  	"github.com/google/certificate-transparency-go/trillian/testdata"
    25  )
    26  
    27  var (
    28  	fixedTime       = time.Date(2017, 9, 7, 12, 15, 23, 0, time.UTC)
    29  	fixedTimeMillis = uint64(fixedTime.UnixNano() / millisPerNano)
    30  	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}
    31  	fakeSignature   = []byte("signed")
    32  )
    33  
    34  func TestGetCTLogID(t *testing.T) {
    35  	block, _ := pem.Decode([]byte(testdata.DemoPublicKey))
    36  	pk, err := x509.ParsePKIXPublicKey(block.Bytes)
    37  	if err != nil {
    38  		t.Fatalf("unexpected error loading public key: %v", err)
    39  	}
    40  
    41  	got, err := GetCTLogID(pk)
    42  	if err != nil {
    43  		t.Fatalf("error getting logid: %v", err)
    44  	}
    45  
    46  	if want := demoLogID; got != want {
    47  		t.Errorf("logID: \n%v want \n%v", got, want)
    48  	}
    49  }
    50  
    51  // Creates a fake signer for use in interaction tests.
    52  // It will always return fakeSig when asked to sign something.
    53  func setupSigner(fakeSig []byte) (crypto.Signer, error) {
    54  	block, _ := pem.Decode([]byte(testdata.DemoPublicKey))
    55  	key, err := x509.ParsePKIXPublicKey(block.Bytes)
    56  	if err != nil {
    57  		return nil, err
    58  	}
    59  
    60  	return testdata.NewSignerWithFixedSig(key, fakeSig), nil
    61  }
    62  

View as plain text