Skip to content

Commit

Permalink
go: make LogID a struct type to match RFC
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddrysdale committed Dec 6, 2016
1 parent 65d3430 commit ee81b72
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions client/logclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func (c *LogClient) addChainWithRetry(ctx context.Context, ctype ct.LogEntryType
return nil, err
}

var logID ct.SHA256Hash
copy(logID[:], resp.ID)
var logID ct.LogID
copy(logID.KeyID[:], resp.ID)
sct := &ct.SignedCertificateTimestamp{
SCTVersion: resp.SCTVersion,
LogID: logID,
Expand Down Expand Up @@ -94,8 +94,8 @@ func (c *LogClient) AddJSON(ctx context.Context, data interface{}) (*ct.SignedCe
if err != nil {
return nil, err
}
var logID ct.SHA256Hash
copy(logID[:], resp.ID)
var logID ct.LogID
copy(logID.KeyID[:], resp.ID)
return &ct.SignedCertificateTimestamp{
SCTVersion: resp.SCTVersion,
LogID: logID,
Expand Down
2 changes: 1 addition & 1 deletion serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func serializeV1SCTHere(sct SignedCertificateTimestamp, here []byte) ([]byte, er
here[0] = byte(sct.SCTVersion)

// Write LogID
copy(here[1:33], sct.LogID[:])
copy(here[1:33], sct.LogID.KeyID[:])

// Write Timestamp
binary.BigEndian.PutUint64(here[33:41], sct.Timestamp)
Expand Down
6 changes: 3 additions & 3 deletions serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ const (
defaultSCTListHexString string = "0476007400380069616d617075626c69636b657973686174776f6669766573697864696765737400000000000004d20000040300097369676e617475726500380069616d617075626c69636b657973686174776f6669766573697864696765737400000000000004d20000040300097369676e6174757265"
)

func defaultSCTLogID() SHA256Hash {
var id SHA256Hash
copy(id[:], defaultSCTLogIDString)
func defaultSCTLogID() LogID {
var id LogID
copy(id.KeyID[:], defaultSCTLogIDString)
return id
}

Expand Down
4 changes: 2 additions & 2 deletions signatures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func sigTestSCTWithSignature(t *testing.T, sig, keyID string) SignedCertificateT
if err != nil {
t.Fatalf("Failed to unmarshal sigTestCertSCTSignatureEC: %v", err)
}
var id SHA256Hash
copy(id[:], mustDehex(t, keyID))
var id LogID
copy(id.KeyID[:], mustDehex(t, keyID))
return SignedCertificateTimestamp{
SCTVersion: V1,
LogID: id,
Expand Down
9 changes: 7 additions & 2 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ func (st SignatureType) String() string {
// (section 3.1).
type ASN1Cert []byte

// LogID holds the hash of the Log's public key (section 3.2).
type LogID struct {
KeyID [32]byte
}

// PreCert represents a Precertificate (section 3.2).
type PreCert struct {
IssuerKeyHash [issuerKeyHashLength]byte
Expand Down Expand Up @@ -237,15 +242,15 @@ type SignedTreeHead struct {
// 3.2, 4.1 and 4.2.
type SignedCertificateTimestamp struct {
SCTVersion Version // The version of the protocol to which the SCT conforms
LogID SHA256Hash // The SHA-256 hash of the (DER-encoded) public key for the Log
LogID LogID // The SHA-256 hash of the (DER-encoded) public key for the Log
Timestamp uint64 // Timestamp (in ms since unix epoch) at which the SCT was issued
Extensions CTExtensions // For future extensions to the protocol
Signature DigitallySigned // The Log's signature for this SCT
}

func (s SignedCertificateTimestamp) String() string {
return fmt.Sprintf("{Version:%d LogId:%s Timestamp:%d Extensions:'%s' Signature:%v}", s.SCTVersion,
base64.StdEncoding.EncodeToString(s.LogID[:]),
base64.StdEncoding.EncodeToString(s.LogID.KeyID[:]),
s.Timestamp,
s.Extensions,
s.Signature)
Expand Down

0 comments on commit ee81b72

Please sign in to comment.