Skip to content

Commit

Permalink
encode fingerprint length correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
aditsachde committed Aug 3, 2024
1 parent 1e53b4e commit c6e6be4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/sunlight/tile_ol.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ func ReadTileLeaf(tile []byte) (e *LogEntry, rest []byte, err error) {
}

// look at first byte to determine the length of the chain
var fingerprintCount uint16
if !s.ReadUint16(&fingerprintCount) {
var fingerprintBytes uint16
if !s.ReadUint16(&fingerprintBytes) {
return nil, s, fmt.Errorf("invalid data tile precert_entry")
}
var fingerprintCount = fingerprintBytes / 32
// then, try to read out that many fingerprints
e.ChainFp = make([][32]byte, 0, fingerprintCount)
for i := uint16(0); i < fingerprintCount; i++ {
Expand Down Expand Up @@ -217,7 +218,8 @@ func AppendTileLeaf(t []byte, e *LogEntry) []byte {
b.AddBytes(e.PreCertificate)
})
}
b.AddUint16(uint16(len(e.ChainFp)))
// A Fingerprint is always 32 bytes and the length is the total number of bytes
b.AddUint16(uint16(len(e.ChainFp) * 32))
for _, fingerprint := range e.ChainFp {
b.AddBytes(fingerprint[:])
}
Expand Down

0 comments on commit c6e6be4

Please sign in to comment.