Source file src/crypto/internal/upki/clubcard_test.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package upki
     6  
     7  import (
     8  	"bytes"
     9  	_ "embed"
    10  	"errors"
    11  	"testing"
    12  
    13  	"golang.org/x/crypto/cryptobyte"
    14  )
    15  
    16  const (
    17  	nontrivialCoverageLow   timestamp = 100
    18  	nontrivialCoverageHigh  timestamp = 200
    19  	nontrivialRevokedSerial           = 0x2a
    20  	nontrivialGoodSerial              = 0x2b
    21  )
    22  
    23  var (
    24  	nontrivialIssuer      = issuerSPKIHash{1, 2, 3}
    25  	nontrivialOtherIssuer = issuerSPKIHash{4, 5, 6}
    26  	nontrivialLog         = logID{9, 9, 9}
    27  
    28  	// nontrivialFilter covers nontrivialLog from timestamps 100 through 200
    29  	// and enrolls two issuers whose serials are listed by nontrivialSerials.
    30  	// Its blocks exercise nontrivial moduli and row offsets.
    31  	//
    32  	//go:embed testdata/nontrivial.filter
    33  	nontrivialFilter []byte
    34  )
    35  
    36  // nontrivialSerials lists every serial enrolled in nontrivialFilter for
    37  // issuer and whether it is revoked. Serials outside these lists are outside
    38  // the filter's universe and have no deterministic verdict.
    39  func nontrivialSerials(issuer issuerSPKIHash) (revoked, good [][]byte) {
    40  	switch issuer {
    41  	case nontrivialIssuer:
    42  		revoked = append(revoked, []byte{nontrivialRevokedSerial})
    43  		for i := range 256 {
    44  			revoked = append(revoked, []byte{0x01, byte(i)})
    45  		}
    46  		for i := range 64 {
    47  			revoked = append(revoked, []byte{0x02, byte(i)})
    48  		}
    49  		good = append(good, []byte{nontrivialGoodSerial}, []byte{0x2c}, []byte{0x2d}, []byte{0x2e})
    50  		for i := range 32 {
    51  			good = append(good, []byte{0x03, byte(i)})
    52  		}
    53  	case nontrivialOtherIssuer:
    54  		for i := range 16 {
    55  			revoked = append(revoked, []byte{0xb0, byte(i)})
    56  		}
    57  		for i := range 8 {
    58  			good = append(good, []byte{0xb1, byte(i)})
    59  		}
    60  	}
    61  
    62  	return revoked, good
    63  }
    64  
    65  func TestParseFilter(t *testing.T) {
    66  	t.Parallel()
    67  
    68  	// Exercise the parser and query path together using a fixture produced by
    69  	// an independent implementation of the clubcard construction algorithm.
    70  	parsed, err := parseFilter(nontrivialFilter)
    71  	if err != nil {
    72  		t.Fatalf("parseFilter: %v", err)
    73  	}
    74  
    75  	// Guard the fixture's shape (see nontrivialFilter): a block whose row
    76  	// depends on t, and blocks that do not all start at row 0.
    77  	if meta := parsed.filter.blocks[nontrivialIssuer]; meta.hModulus < 2 || meta.hRank < 2 {
    78  		t.Fatalf("nontrivialIssuer block has hModulus %d and hRank %d; want a modulus above 1 and at least two columns",
    79  			meta.hModulus, meta.hRank)
    80  	}
    81  	var hOffset, gOffset bool
    82  	for _, meta := range parsed.filter.blocks {
    83  		hOffset = hOffset || meta.hOffset != 0
    84  		gOffset = gOffset || meta.gOffset != 0
    85  	}
    86  	if !hOffset || !gOffset {
    87  		t.Fatalf("fixture has a nonzero hOffset: %v, gOffset: %v; want both", hOffset, gOffset)
    88  	}
    89  
    90  	covered := SCT{logID: nontrivialLog, timestamp: nontrivialCoverageLow}
    91  	tests := []struct {
    92  		name string
    93  		key  lookupKey
    94  		scts []SCT
    95  		want filterStatus
    96  	}{
    97  		{
    98  			name: "revoked",
    99  			key:  newLookupKey(nontrivialIssuer, []byte{nontrivialRevokedSerial}),
   100  			scts: []SCT{covered},
   101  			want: statusRevoked,
   102  		},
   103  		{
   104  			name: "not revoked",
   105  			key:  newLookupKey(nontrivialIssuer, []byte{nontrivialGoodSerial}),
   106  			scts: []SCT{covered},
   107  			want: statusGood,
   108  		},
   109  		{
   110  			name: "coverage upper bound",
   111  			key:  newLookupKey(nontrivialIssuer, []byte{nontrivialRevokedSerial}),
   112  			scts: []SCT{{logID: nontrivialLog, timestamp: nontrivialCoverageHigh}},
   113  			want: statusRevoked,
   114  		},
   115  		{
   116  			name: "timestamp not covered",
   117  			key:  newLookupKey(nontrivialIssuer, []byte{nontrivialRevokedSerial}),
   118  			scts: []SCT{{logID: nontrivialLog, timestamp: nontrivialCoverageHigh + 1}},
   119  			want: statusNotCovered,
   120  		},
   121  		{
   122  			name: "log not covered",
   123  			key:  newLookupKey(nontrivialIssuer, []byte{nontrivialRevokedSerial}),
   124  			scts: []SCT{{logID: logID{0xff}, timestamp: nontrivialCoverageLow}},
   125  			want: statusNotCovered,
   126  		},
   127  		{
   128  			name: "issuer not enrolled",
   129  			key:  newLookupKey(issuerSPKIHash{0xff}, []byte{nontrivialRevokedSerial}),
   130  			scts: []SCT{covered},
   131  			want: statusNotEnrolled,
   132  		},
   133  	}
   134  	for _, test := range tests {
   135  		t.Run(test.name, func(t *testing.T) {
   136  			t.Parallel()
   137  			if got := parsed.contains(&test.key, test.scts); got != test.want {
   138  				t.Errorf("contains = %v, want %v", got, test.want)
   139  			}
   140  		})
   141  	}
   142  
   143  	// Every enrolled serial must get the verdict the reference builder gave
   144  	// it. Across hundreds of serials in two blocks, a wrong row selection
   145  	// (the wrong hash limb for t, or a mishandled block offset) cannot pass
   146  	// by chance.
   147  	t.Run("all enrolled serials", func(t *testing.T) {
   148  		t.Parallel()
   149  		for _, issuer := range []issuerSPKIHash{nontrivialIssuer, nontrivialOtherIssuer} {
   150  			revoked, good := nontrivialSerials(issuer)
   151  			for _, serial := range revoked {
   152  				key := newLookupKey(issuer, serial)
   153  				if got := parsed.contains(&key, []SCT{covered}); got != statusRevoked {
   154  					t.Errorf("issuer %x serial %x: contains = %v, want statusRevoked", issuer[:3], serial, got)
   155  				}
   156  			}
   157  			for _, serial := range good {
   158  				key := newLookupKey(issuer, serial)
   159  				if got := parsed.contains(&key, []SCT{covered}); got != statusGood {
   160  					t.Errorf("issuer %x serial %x: contains = %v, want statusGood", issuer[:3], serial, got)
   161  				}
   162  			}
   163  		}
   164  	})
   165  }
   166  
   167  // TestParseFilterRankZero covers the compact encoding of an empty block
   168  // (§3.1 "Rank zero blocks"): no filter columns, no exceptions, and every
   169  // query answers not revoked, or revoked when the block is inverted. CRLite
   170  // uses such blocks for issuers with no revocations and, inverted, for
   171  // issuers whose certificates are all revoked, so the parser and query path
   172  // must accept them even though the filter carries no ribbon data.
   173  func TestParseFilterRankZero(t *testing.T) {
   174  	t.Parallel()
   175  
   176  	const (
   177  		coverageLow  timestamp = 10
   178  		coverageHigh timestamp = 20
   179  		queryTime    timestamp = 15
   180  	)
   181  	issuer := issuerSPKIHash{1}
   182  	log := logID{2}
   183  	for _, inverted := range []bool{false, true} {
   184  		var invertedByte uint8
   185  		if inverted {
   186  			invertedByte = 1
   187  		}
   188  		parsed, err := parseFilter(encodeTestFilter(
   189  			[]testCoverage{{logID: log, low: coverageLow, high: coverageHigh}},
   190  			[]testBlock{{issuer: issuer, inverted: invertedByte}},
   191  			0,
   192  		))
   193  		if err != nil {
   194  			t.Fatalf("inverted=%v: parseFilter: %v", inverted, err)
   195  		}
   196  		key := newLookupKey(issuer, []byte("serial"))
   197  		want := statusGood
   198  		if inverted {
   199  			want = statusRevoked
   200  		}
   201  		if got := parsed.contains(&key, []SCT{{logID: log, timestamp: queryTime}}); got != want {
   202  			t.Errorf("inverted=%v: contains = %v, want %v", inverted, got, want)
   203  		}
   204  	}
   205  }
   206  
   207  func TestParseFilterMalformed(t *testing.T) {
   208  	t.Parallel()
   209  
   210  	const (
   211  		coverageLow  timestamp = 10
   212  		coverageHigh timestamp = 20
   213  	)
   214  	issuer := issuerSPKIHash{1}
   215  	log := logID{2}
   216  	valid := encodeTestFilter(
   217  		[]testCoverage{{logID: log, low: coverageLow, high: coverageHigh}},
   218  		[]testBlock{{issuer: issuer}},
   219  		0,
   220  	)
   221  	version := bytes.Clone(valid)
   222  	version[0] = 5
   223  	reserved := bytes.Clone(valid)
   224  	reserved[1] = 1
   225  	tests := []struct {
   226  		name string
   227  		data []byte
   228  		want error
   229  	}{
   230  		{"unsupported version", version, errUnsupportedFormat},
   231  		{"nonzero reserved byte", reserved, errDeserialize},
   232  		{"trailing data", append(bytes.Clone(valid), 0), errDeserialize},
   233  		{"duplicate coverage log", encodeTestFilter(
   234  			[]testCoverage{
   235  				{logID: log, low: coverageLow, high: coverageHigh},
   236  				{logID: log, low: coverageHigh + 10, high: coverageHigh + 20},
   237  			},
   238  			nil, 0), errDeserialize},
   239  		{"duplicate block", encodeTestFilter(nil,
   240  			[]testBlock{{issuer: issuer}, {issuer: issuer}}, 0), errDeserialize},
   241  		{"invalid inverted flag", encodeTestFilter(nil,
   242  			[]testBlock{{issuer: issuer, inverted: 2}}, 0), errDeserialize},
   243  		{"rank exceeds columns", encodeTestFilter(nil,
   244  			[]testBlock{{issuer: issuer, rank: 1}}, 0), errDeserialize},
   245  		{"inflated coverage count", []byte{4, 0, 0xff, 0xff}, errDeserialize},
   246  		{"inflated block count", []byte{4, 0, 0, 0, 0xff, 0xff, 0xff, 0xff}, errDeserialize},
   247  		{"truncated header", valid[:1], errDeserialize},
   248  		{"truncated coverage", valid[:10], errDeserialize},
   249  		{"truncated block", valid[:len(valid)-8], errDeserialize},
   250  		{"truncated exact column", valid[:len(valid)-1], errDeserialize},
   251  	}
   252  	for _, test := range tests {
   253  		t.Run(test.name, func(t *testing.T) {
   254  			t.Parallel()
   255  			if _, err := parseFilter(test.data); !errors.Is(err, test.want) {
   256  				t.Fatalf("parseFilter error = %v, want %v", err, test.want)
   257  			}
   258  		})
   259  	}
   260  }
   261  
   262  func FuzzParseFilter(f *testing.F) {
   263  	f.Add(nontrivialFilter)
   264  	f.Add(encodeTestFilter(
   265  		[]testCoverage{{logID: logID{1}, low: 10, high: 20}},
   266  		[]testBlock{{issuer: issuerSPKIHash{2}, inverted: 1}},
   267  		0,
   268  	))
   269  	// A bare v4 version and reserved byte reaches the first required field
   270  	// without carrying any of the following coverage or filter structure.
   271  	f.Add([]byte{4, 0})
   272  
   273  	f.Fuzz(func(t *testing.T, data []byte) {
   274  		parsed, err := parseFilter(data)
   275  		if err != nil {
   276  			return
   277  		}
   278  
   279  		// Probe accepted filters using their coverage bounds, several issuers,
   280  		// and several serial shapes so unsafe metadata triggers a panic.
   281  		var scts []SCT
   282  		for id, interval := range parsed.coverage {
   283  			scts = append(scts,
   284  				SCT{logID: id, timestamp: interval.low},
   285  				SCT{logID: id, timestamp: interval.high})
   286  			if len(scts) >= 8 {
   287  				break
   288  			}
   289  		}
   290  		scts = append(scts, SCT{logID: logID{0xff}})
   291  
   292  		queried := 0
   293  		for issuer := range parsed.filter.blocks {
   294  			for _, serial := range [][]byte{nil, {1}, {0xab, 0xcd}} {
   295  				key := newLookupKey(issuer, serial)
   296  				parsed.contains(&key, scts)
   297  			}
   298  			queried++
   299  			if queried == 4 {
   300  				break
   301  			}
   302  		}
   303  		key := newLookupKey(issuerSPKIHash{0x42}, []byte{1})
   304  		parsed.contains(&key, scts)
   305  	})
   306  }
   307  
   308  func TestFilterContains(t *testing.T) {
   309  	t.Parallel()
   310  
   311  	// Rank-zero blocks encode an empty revoked set without allocating filter
   312  	// columns. Inversion changes that empty set into the whole issuer universe.
   313  	t.Run("rank zero", func(t *testing.T) {
   314  		t.Parallel()
   315  
   316  		f := new(filter)
   317  		if f.contains(&blockMeta{inverted: true}, [32]byte{}, nil) != true {
   318  			t.Error("inverted rank-zero block did not contain the query")
   319  		}
   320  		if f.contains(&blockMeta{}, [32]byte{}, nil) != false {
   321  			t.Error("non-inverted rank-zero block contained the query")
   322  		}
   323  	})
   324  
   325  	// Exception serials are insertion failures from the exact filter. They are
   326  	// non-members before the block's final inversion is applied.
   327  	t.Run("exceptions", func(t *testing.T) {
   328  		t.Parallel()
   329  
   330  		f := &filter{x: [][]uint64{make([]uint64, 4)}, y: make([]uint64, 4)}
   331  		for _, inverted := range []bool{false, true} {
   332  			meta := &blockMeta{
   333  				hModulus: 1,
   334  				hRank:    1,
   335  				gModulus: 1,
   336  				exceptions: map[string]struct{}{
   337  					"exception": {},
   338  				},
   339  				inverted: inverted,
   340  			}
   341  			if got := f.contains(meta, [32]byte{}, []byte("exception")); got != inverted {
   342  				t.Errorf("inverted=%v exception result = %v, want %v", inverted, got, inverted)
   343  			}
   344  			if got := f.contains(meta, [32]byte{}, []byte("other")); got == inverted {
   345  				t.Errorf("inverted=%v non-exception result = %v, want %v", inverted, got, !inverted)
   346  			}
   347  		}
   348  	})
   349  
   350  	// A query is rejected when its approximate-filter dot product is nonzero.
   351  	// Pairing the query's explicit bit with its implicit low bit makes the dot
   352  	// product zero and demonstrates the corresponding acceptance path.
   353  	t.Run("approximate column", func(t *testing.T) {
   354  		t.Parallel()
   355  
   356  		var hash [32]byte
   357  		hash[0] = 0x04 // bit 2, in addition to the implicit bit 0
   358  		x := [][]uint64{make([]uint64, 4)}
   359  		setFilterRowBit(x, 0, 2)
   360  		f := &filter{x: x, y: make([]uint64, 4)}
   361  		meta := &blockMeta{hModulus: 1, hRank: 1, gModulus: 1}
   362  		if f.contains(meta, hash, nil) {
   363  			t.Error("query with nonzero approximate dot product was accepted")
   364  		}
   365  
   366  		setFilterRowBit(x, 0, 0)
   367  		if !f.contains(meta, hash, nil) {
   368  			t.Error("query with zero approximate dot product was rejected")
   369  		}
   370  	})
   371  
   372  	// Every approximate column up to hRank participates in the query. Planting
   373  	// the rejecting bit in each column in turn confirms none are skipped.
   374  	t.Run("multiple approximate columns", func(t *testing.T) {
   375  		t.Parallel()
   376  
   377  		var hash [32]byte
   378  		hash[0] = 0x04
   379  		meta := &blockMeta{hModulus: 1, hRank: 3, gModulus: 1}
   380  		for column := range int(meta.hRank) {
   381  			x := [][]uint64{make([]uint64, 4), make([]uint64, 4), make([]uint64, 4)}
   382  			setFilterRowBit(x, column, 2)
   383  			f := &filter{x: x, y: make([]uint64, 4)}
   384  			if f.contains(meta, hash, nil) {
   385  				t.Errorf("query rejected by column %d was accepted", column)
   386  			}
   387  		}
   388  	})
   389  
   390  	// hOffset selects the issuer block's window within a shared column. A bit
   391  	// inside that window must affect the result, and the same bit outside it
   392  	// must not.
   393  	t.Run("block row offset", func(t *testing.T) {
   394  		t.Parallel()
   395  
   396  		var hash [32]byte
   397  		hash[0] = 0x04
   398  		x := [][]uint64{make([]uint64, 8)}
   399  		setFilterRowBit(x, 0, 256+2)
   400  		f := &filter{x: x, y: make([]uint64, 4)}
   401  		meta := &blockMeta{hOffset: 256, hModulus: 1, hRank: 1, gModulus: 1}
   402  		if f.contains(meta, hash, nil) {
   403  			t.Error("query rejected inside the block window was accepted")
   404  		}
   405  
   406  		clear(x[0])
   407  		setFilterRowBit(x, 0, 2)
   408  		if !f.contains(meta, hash, nil) {
   409  			t.Error("bit outside the block window affected the query")
   410  		}
   411  	})
   412  
   413  	// The exact-filter vector is evaluated after the approximate columns. A
   414  	// nonzero exact dot product rejects a query that passed the earlier
   415  	// stage, and pairing the query's bit with its implicit low bit makes the
   416  	// product zero again and accepts it.
   417  	t.Run("exact column", func(t *testing.T) {
   418  		t.Parallel()
   419  
   420  		var hash [32]byte
   421  		hash[0] = 0x04 // bit 2, in addition to the implicit bit 0
   422  		y := make([]uint64, 4)
   423  		setFilterRowBit([][]uint64{y}, 0, 2)
   424  		f := &filter{x: [][]uint64{make([]uint64, 4)}, y: y}
   425  		meta := &blockMeta{hModulus: 1, hRank: 1, gModulus: 1}
   426  		if f.contains(meta, hash, nil) {
   427  			t.Error("query with nonzero exact dot product was accepted")
   428  		}
   429  
   430  		setFilterRowBit([][]uint64{y}, 0, 0)
   431  		if !f.contains(meta, hash, nil) {
   432  			t.Error("query with zero exact dot product was rejected")
   433  		}
   434  	})
   435  
   436  	// A zero exact modulus does not skip the exact filter: the reference
   437  	// implementation reduces modulo max(1, m), so the row is gOffset and a
   438  	// bit there still rejects the query.
   439  	t.Run("exact column zero modulus", func(t *testing.T) {
   440  		t.Parallel()
   441  
   442  		var hash [32]byte
   443  		hash[0] = 0x04
   444  		y := make([]uint64, 4)
   445  		setFilterRowBit([][]uint64{y}, 0, 100+2)
   446  		f := &filter{x: [][]uint64{make([]uint64, 4)}, y: y}
   447  		meta := &blockMeta{hModulus: 1, hRank: 1, gOffset: 100, gModulus: 0}
   448  		if f.contains(meta, hash, nil) {
   449  			t.Error("query rejected by the exact filter at gOffset was accepted")
   450  		}
   451  	})
   452  
   453  	// The blocks above use a modulus of 1, which pins the probed row at the
   454  	// block offset whatever the hash. With a larger modulus the row is
   455  	// offset + t mod modulus, where t is the high 64 bits of the hash read
   456  	// little-endian (§4.3 step 3), so bytes 24 through 31 select the row.
   457  	// Plant the rejecting bit at that row, then at the row the low limb
   458  	// would select, to pin which end of the hash t is taken from.
   459  	t.Run("approximate row selection", func(t *testing.T) {
   460  		t.Parallel()
   461  
   462  		var hash [32]byte
   463  		hash[0] = 0x04  // coefficient bit 2; the low limb is 5 once bit 0 is forced
   464  		hash[24] = 0x0d // t = 13
   465  		const offset, modulus = 100, 7
   466  		selectedRow := uint64(offset + 13%modulus)
   467  		lowLimbRow := uint64(offset + 5%modulus)
   468  		meta := &blockMeta{hOffset: offset, hModulus: modulus, hRank: 1, gModulus: 1}
   469  		x := [][]uint64{make([]uint64, 4)}
   470  		setFilterRowBit(x, 0, selectedRow+2)
   471  		f := &filter{x: x, y: make([]uint64, 4)}
   472  		if f.contains(meta, hash, nil) {
   473  			t.Error("query rejected at the row selected by t was accepted")
   474  		}
   475  
   476  		clear(x[0])
   477  		setFilterRowBit(x, 0, lowLimbRow+2)
   478  		if !f.contains(meta, hash, nil) {
   479  			t.Error("bit at the row selected by the low limb affected the query")
   480  		}
   481  	})
   482  
   483  	t.Run("exact row selection", func(t *testing.T) {
   484  		t.Parallel()
   485  
   486  		var hash [32]byte
   487  		hash[0] = 0x04
   488  		hash[24] = 0x0d
   489  		const offset, modulus = 100, 7
   490  		selectedRow := uint64(offset + 13%modulus)
   491  		lowLimbRow := uint64(offset + 5%modulus)
   492  		meta := &blockMeta{hModulus: 1, hRank: 1, gOffset: offset, gModulus: modulus}
   493  		y := make([]uint64, 4)
   494  		setFilterRowBit([][]uint64{y}, 0, selectedRow+2)
   495  		f := &filter{x: [][]uint64{make([]uint64, 4)}, y: y}
   496  		if f.contains(meta, hash, nil) {
   497  			t.Error("query rejected at the exact row selected by t was accepted")
   498  		}
   499  
   500  		clear(y)
   501  		setFilterRowBit([][]uint64{y}, 0, lowLimbRow+2)
   502  		if !f.contains(meta, hash, nil) {
   503  			t.Error("bit at the exact row selected by the low limb affected the query")
   504  		}
   505  	})
   506  }
   507  
   508  func TestBitsXorIsZero(t *testing.T) {
   509  	t.Parallel()
   510  
   511  	// Cover empty and nonzero products, a query window crossing a uint64
   512  	// boundary, and the specified zero-extension beyond a short column.
   513  	tests := []struct {
   514  		name   string
   515  		column []uint64
   516  		offset uint64
   517  		coef   [ribbonWidth]uint64
   518  		want   bool
   519  	}{
   520  		{"zero", nil, 0, [ribbonWidth]uint64{1}, true},
   521  		{"one", []uint64{1}, 0, [ribbonWidth]uint64{1}, false},
   522  		{"crosses limb", []uint64{0, 1}, 63, [ribbonWidth]uint64{2}, false},
   523  		{"past end", []uint64{^uint64(0)}, 64, [ribbonWidth]uint64{^uint64(0)}, true},
   524  	}
   525  	for _, test := range tests {
   526  		t.Run(test.name, func(t *testing.T) {
   527  			t.Parallel()
   528  			if got := bitsXorIsZero(test.column, test.offset, test.coef); got != test.want {
   529  				t.Errorf("bitsXorIsZero = %v, want %v", got, test.want)
   530  			}
   531  		})
   532  	}
   533  }
   534  
   535  func setFilterRowBit(columns [][]uint64, column int, row uint64) {
   536  	columns[column][row/64] |= uint64(1) << (row % 64)
   537  }
   538  
   539  type testCoverage struct {
   540  	logID     logID
   541  	low, high timestamp
   542  }
   543  
   544  type testBlock struct {
   545  	issuer     issuerSPKIHash
   546  	hModulus   uint32
   547  	rank       uint8
   548  	hOffset    uint32
   549  	gModulus   uint32
   550  	gOffset    uint32
   551  	inverted   uint8
   552  	exceptions [][]byte
   553  }
   554  
   555  func encodeTestFilter(coverage []testCoverage, blocks []testBlock, columns uint8) []byte {
   556  	// This mirrors the C2SP upki-revocation v1.0.0 Clubcard wire format,
   557  	// restricted to the fields and zero-valued columns needed by these tests.
   558  	var builder cryptobyte.Builder
   559  	builder.AddUint8(4)
   560  	builder.AddUint8(0)
   561  	builder.AddUint16(uint16(len(coverage)))
   562  	for _, item := range coverage {
   563  		builder.AddBytes(item.logID[:])
   564  		builder.AddUint64(uint64(item.low))
   565  		builder.AddUint64(uint64(item.high))
   566  	}
   567  	builder.AddUint32(uint32(len(blocks)))
   568  	for _, block := range blocks {
   569  		builder.AddBytes(block.issuer[:])
   570  		builder.AddUint32(block.hModulus)
   571  		builder.AddUint8(block.rank)
   572  		builder.AddUint32(block.hOffset)
   573  		builder.AddUint32(block.gModulus)
   574  		builder.AddUint32(block.gOffset)
   575  		builder.AddUint8(block.inverted)
   576  		builder.AddUint16(uint16(len(block.exceptions)))
   577  		for _, serial := range block.exceptions {
   578  			builder.AddUint8LengthPrefixed(func(builder *cryptobyte.Builder) {
   579  				builder.AddBytes(serial)
   580  			})
   581  		}
   582  	}
   583  	builder.AddUint8(columns)
   584  	for range columns {
   585  		builder.AddUint32(0)
   586  	}
   587  	builder.AddUint32(0)
   588  
   589  	return builder.BytesOrPanic()
   590  }
   591  

View as plain text