Skip to content

Commit

Permalink
Fix var / package collisions and extra parens (google#565)
Browse files Browse the repository at this point in the history
* Fix var / package collisions and extra parens

These fixes were applied automatically but should be safe.

* Review fixes

* Fix var / package collisions and extra parens

These fixes were applied automatically but should be safe.

* Update submission/distributor.go

Co-Authored-By: Rob Percival <robpercival@google.com>

* Update submission/loglist_manager.go

Co-Authored-By: Rob Percival <robpercival@google.com>

* Revert asn1 change again.
  • Loading branch information
Martin2112 authored Jul 17, 2019
1 parent 9103e03 commit add54b7
Show file tree
Hide file tree
Showing 34 changed files with 266 additions and 256 deletions.
2 changes: 1 addition & 1 deletion client/ctclient/ctclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func findTimestamp(ctx context.Context, logClient *client.LogClient) {
idx := sort.Search(int(sth.TreeSize), func(idx int) bool {
glog.V(1).Infof("check timestamp at index %d", idx)
entry := getEntry(int64(idx))
return (entry.Leaf.TimestampedEntry.Timestamp >= uint64(target))
return entry.Leaf.TimestampedEntry.Timestamp >= uint64(target)
})
when := ct.TimestampToTime(uint64(target))
if idx >= int(sth.TreeSize) {
Expand Down
2 changes: 1 addition & 1 deletion ctpolicy/ctpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (groups LogPolicyData) TotalLogs() int {
// CTPolicy interface describes requirements determined for logs in terms of
// per-group-submit.
type CTPolicy interface {
// Provides info on Log-grouping. Returns an error if loglist provided is
// LogsByGroup provides info on Log-grouping. Returns an error if loglist provided is
// not sufficient to satisfy policy.
// The data output is formed even when error returned.
LogsByGroup(cert *x509.Certificate, approved *loglist.LogList) (LogPolicyData, error)
Expand Down
6 changes: 3 additions & 3 deletions ctpolicy/ctpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ func getTestCertPEMLongOriginal() *x509.Certificate {

func sampleLogList(t *testing.T) *loglist.LogList {
t.Helper()
var loglist loglist.LogList
err := json.Unmarshal([]byte(testdata.SampleLogList), &loglist)
var ll loglist.LogList
err := json.Unmarshal([]byte(testdata.SampleLogList), &ll)
if err != nil {
t.Fatalf("Unable to Unmarshal testdata.SampleLogList %v", err)
}
return &loglist
return &ll
}

func TestLifetimeInMonths(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions ctpolicy/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestWeightedRandomSampleDef(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
gotItem, err := weightedRandomSample(tc.weights)
if gotErr := (err != nil); gotErr != tc.wantErr {
if gotErr := err != nil; gotErr != tc.wantErr {
t.Fatalf("weightedRandomSample(%v) = (_, error: %v), want err? %t", tc.weights, err, tc.wantErr)
}
if gotItem != tc.wantItem {
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestWeightedRandomSampleInDef(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
gotItem, err := weightedRandomSample(tc.weights)
if gotErr := (err != nil); gotErr != tc.wantErr {
if gotErr := err != nil; gotErr != tc.wantErr {
t.Fatalf("weightedRandomSample(%v) = (_, error: %v), want err? %t", tc.weights, err, tc.wantErr)
}
for _, i := range tc.wantOneOf {
Expand Down
2 changes: 1 addition & 1 deletion ctutil/ctutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestVerifySCT(t *testing.T) {
}

err = VerifySCT(pk, chain, &sct, test.embedded)
if gotErr := (err != nil); gotErr != test.wantErr {
if gotErr := err != nil; gotErr != test.wantErr {
t.Errorf("%s: VerifySCT(_,_,_, %t) = %v, want error? %t", test.desc, test.embedded, err, test.wantErr)
}
}
Expand Down
4 changes: 2 additions & 2 deletions ctutil/sctcheck/sctcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func main() {
glog.Errorf("%s: failed to get cert chain: %v", arg, err)
continue
}
glog.Errorf("Found %d external SCTs for %q, of which %d were validated", (valid + invalid), arg, valid)
glog.Errorf("Found %d external SCTs for %q, of which %d were validated", valid+invalid, arg, valid)
totalInvalid += invalid
} else {
// Treat the argument as a certificate file to load.
Expand All @@ -100,7 +100,7 @@ func main() {
}
// Check the chain for embedded SCTs.
valid, invalid = checkChain(ctx, lf, chain, ll, hc)
glog.Errorf("Found %d embedded SCTs for %q, of which %d were validated", (valid + invalid), arg, valid)
glog.Errorf("Found %d embedded SCTs for %q, of which %d were validated", valid+invalid, arg, valid)
totalInvalid += invalid
}
if totalInvalid > 0 {
Expand Down
38 changes: 21 additions & 17 deletions fixchain/fixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,11 @@ func (f *Fixer) updateCounters(chains [][]*x509.Certificate, ferrs []*FixError)
atomic.AddUint32(&f.reconstructed, 1)
}

type chainSlice struct {
chains [][]*x509.Certificate
}

func min(a, b int) int {
if a < b {
return a
}
return b
}

// sort.Sort(data Interface) for chainSlice - uses data.Len, data.Less & data.Swap.
// Sort will sort the chains contained within the chainSlice. The chains will
// be sorted in order of the first certificate in the chain, i.e. their leaf
// certificate. If two chains have equal leaf certificates, they will be sorted
// by the second certificate in the chain, and so on. By this logic, a chain
// that is a subchain of another chain beginning at the leaf of the other chain,
// chainSlice contains chains of certificates. Applying Sort will sort in
// order of the first certificate in the chain, i.e. their leaf certificate.
// If two chains have equal leaf certificates, they will be sorted by the
// second certificate in the chain, and so on. By this logic, a chain that
// is a subchain of another chain beginning at the leaf of the other chain,
// will come before the other chain after sorting.
//
// Example:
Expand All @@ -128,7 +116,21 @@ func min(a, b int) int {
// A -> B -> C
// A -> C
// D
type chainSlice struct {
chains [][]*x509.Certificate
}

func min(a, b int) int {
if a < b {
return a
}
return b
}

// Len implements sort.Sort(data Interface) for chainSlice.
func (c chainSlice) Len() int { return len(c.chains) }

// Less implements sort.Sort interface for chainSlice.
func (c chainSlice) Less(i, j int) bool {
chi := c.chains[i]
chj := c.chains[j]
Expand All @@ -139,6 +141,8 @@ func (c chainSlice) Less(i, j int) bool {
}
return len(chi) < len(chj)
}

// Swap implements sort.Sort interface for chainSlice.
func (c chainSlice) Swap(i, j int) {
t := c.chains[i]
c.chains[i] = c.chains[j]
Expand Down
8 changes: 7 additions & 1 deletion fixchain/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ func hashBag(chain []*x509.Certificate) [hashSize]byte {
return hashChain(b.certs)
}

// bag is a collection of certificates that can contain duplicates.
// Applying sort will order them by their raw representation.
type bag struct {
certs []*x509.Certificate
}

// sort.Sort(data Interface) for bag - uses data.Len, data.Less & data.Swap
// Len implements sort.Sort(data Interface) for bag.
func (b bag) Len() int { return len(b.certs) }

// Less implements sort.Sort(data Interface) for bag.
func (b bag) Less(i, j int) bool {
ci := b.certs[i].Raw
cj := b.certs[j].Raw
Expand All @@ -78,6 +82,8 @@ func (b bag) Less(i, j int) bool {
}
return false
}

// Swap implements sort.Sort(data Interface) for bag.
func (b bag) Swap(i, j int) {
t := b.certs[i]
b.certs[i] = b.certs[j]
Expand Down
4 changes: 2 additions & 2 deletions gossip/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func (h *Handler) HandleSTHPollination(rw http.ResponseWriter, req *http.Request
return
}

json := json.NewEncoder(rw)
if err := json.Encode(*rp); err != nil {
encoder := json.NewEncoder(rw)
if err := encoder.Encode(*rp); err != nil {
writeErrorResponse(&rw, http.StatusInternalServerError, fmt.Sprintf("Couldn't encode pollination to return: %v", err))
return
}
Expand Down
8 changes: 4 additions & 4 deletions gossip/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,19 @@ func mustCreateSignatureVerifiers(t *testing.T) SignatureVerifierMap {

func sctFeedbackFromString(t *testing.T, s string) SCTFeedback {
t.Helper()
json := json.NewDecoder(strings.NewReader(s))
decoder := json.NewDecoder(strings.NewReader(s))
var f SCTFeedback
if err := json.Decode(&f); err != nil {
if err := decoder.Decode(&f); err != nil {
t.Fatalf("Failed to parse JSON: %v", err)
}
return f
}

func sthPollinationFromString(t *testing.T, s string) STHPollination {
t.Helper()
json := json.NewDecoder(strings.NewReader(s))
decoder := json.NewDecoder(strings.NewReader(s))
var f STHPollination
if err := json.Decode(&f); err != nil {
if err := decoder.Decode(&f); err != nil {
t.Fatalf("Failed to parse JSON: %v", err)
}
return f
Expand Down
6 changes: 3 additions & 3 deletions gossip/minimal/goshawk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ func TestValidateSTH(t *testing.T) {
}
s := httptest.NewServer(handler)
defer s.Close()
client, err := client.New(s.URL+"/ct/v1/get-sth-consistency", nil, jsonclient.Options{PublicKey: argonKey})
cl, err := client.New(s.URL+"/ct/v1/get-sth-consistency", nil, jsonclient.Options{PublicKey: argonKey})
if err != nil {
t.Fatalf("failed to create client: %v", err)
t.Fatalf("failed to create cl: %v", err)
}
o := originLog{
reporter: &incident.LoggingReporter{},
logConfig: logConfig{
Name: "argon2018",
URL: "http://ct.googleapis.com/logs/argon2018",
Log: client,
Log: cl,
},
}
sthInfo1 := x509ext.LogSTHInfo{
Expand Down
2 changes: 1 addition & 1 deletion ingestor/ranges/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestAddingSubRanges(t *testing.T) {
now = now.Add(time.Second)

err := tr.AddSubRange(a.first, a.last)
if gotErr := (err != nil); gotErr != a.wantErr {
if gotErr := err != nil; gotErr != a.wantErr {
t.Errorf("%s: %d: AddSubRange(%d, %d): got err? %t, want? %t (err %v)", test.desc, i, a.first, a.last, gotErr, a.wantErr, err)
}

Expand Down
4 changes: 2 additions & 2 deletions logid/logid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestFromBytes(t *testing.T) {

for _, test := range tests {
got, err := FromBytes(toBytes(test.in, test.size))
if gotErr := (err != nil); gotErr != test.wantErr {
if gotErr := err != nil; gotErr != test.wantErr {
t.Errorf("FromBytes(%q): got err? %t, want? %t (err=%v)", test.in, gotErr, test.wantErr, err)
}
if err == nil && !reflect.DeepEqual(&got, test.want) {
Expand All @@ -79,7 +79,7 @@ func TestFromB64(t *testing.T) {

for _, test := range tests {
got, err := FromB64(test.in)
if gotErr := (err != nil); gotErr != test.wantErr {
if gotErr := err != nil; gotErr != test.wantErr {
t.Errorf("FromB64(%q): got err? %t, want? %t (err=%v)", test.in, gotErr, test.wantErr, err)
}
if err == nil && !reflect.DeepEqual(&got, test.want) {
Expand Down
30 changes: 15 additions & 15 deletions loglist2/loglist2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ func TestFindLogByURL(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
log := sampleLogList.FindLogByURL(test.in)
l := sampleLogList.FindLogByURL(test.in)
got := ""
if log != nil {
got = log.Description
if l != nil {
got = l.Description
}
if got != test.want {
t.Errorf("FindLogByURL(%q)=%q, want %q", test.in, got, test.want)
Expand Down Expand Up @@ -262,10 +262,10 @@ func TestFindLogByKeyhash(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
var hash [sha256.Size]byte
copy(hash[:], test.in)
log := sampleLogList.FindLogByKeyHash(hash)
l := sampleLogList.FindLogByKeyHash(hash)
got := ""
if log != nil {
got = log.Description
if l != nil {
got = l.Description
}
if got != test.want {
t.Errorf("FindLogByKeyHash(%x)=%q, want %q", test.in, got, test.want)
Expand Down Expand Up @@ -305,8 +305,8 @@ func TestFindLogByKeyhashPrefix(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
logs := sampleLogList.FindLogByKeyHashPrefix(test.in)
got := make([]string, len(logs))
for i, log := range logs {
got[i] = log.Description
for i, l := range logs {
got[i] = l.Description
}
sort.Strings(got)
if !reflect.DeepEqual(got, test.want) {
Expand Down Expand Up @@ -335,10 +335,10 @@ func TestFindLogByKey(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
log := sampleLogList.FindLogByKey(test.in)
l := sampleLogList.FindLogByKey(test.in)
got := ""
if log != nil {
got = log.Description
if l != nil {
got = l.Description
}
if got != test.want {
t.Errorf("FindLogByKey(%x)=%q, want %q", test.in, got, test.want)
Expand Down Expand Up @@ -403,8 +403,8 @@ func TestFuzzyFindLog(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
logs := sampleLogList.FuzzyFindLog(test.in)
got := make([]string, len(logs))
for i, log := range logs {
got[i] = log.Description
for i, l := range logs {
got[i] = l.Description
}
if !reflect.DeepEqual(got, test.want) {
t.Errorf("FuzzyFindLog(%q)=%v, want %v", test.in, got, test.want)
Expand Down Expand Up @@ -447,8 +447,8 @@ func TestLogStatesString(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
log := sampleLogList.FindLogByURL(test.logURL)
if got := log.State.String(); got != test.want {
l := sampleLogList.FindLogByURL(test.logURL)
if got := l.State.String(); got != test.want {
t.Errorf("%q: Log.State.String() = %s, want %s", test.logURL, got, test.want)
}
})
Expand Down
4 changes: 2 additions & 2 deletions preload/preloader/preloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func main() {
PrecertOnly: *precertsOnly,
NumWorkers: *numWorkers,
}
scanner := scanner.NewScanner(fetchLogClient, opts)
s := scanner.NewScanner(fetchLogClient, opts)

bufferSize := 10 * *parallelSubmit
certs := make(chan *ct.LogEntry, bufferSize)
Expand Down Expand Up @@ -241,7 +241,7 @@ func main() {
}
precerts <- entry
}
scanner.Scan(ctx, addChainFunc, addPreChainFunc)
s.Scan(ctx, addChainFunc, addPreChainFunc)

close(certs)
close(precerts)
Expand Down
6 changes: 3 additions & 3 deletions scanner/scanlog/scanlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ func main() {
Matcher: matcher,
NumWorkers: *numWorkers,
}
scanner := scanner.NewScanner(logClient, opts)
s := scanner.NewScanner(logClient, opts)

ctx := context.Background()
if *printChains {
scanner.Scan(ctx, logFullChain, logFullChain)
s.Scan(ctx, logFullChain, logFullChain)
} else {
scanner.Scan(ctx, logCertInfo, logPrecertInfo)
s.Scan(ctx, logCertInfo, logPrecertInfo)
}
}
4 changes: 2 additions & 2 deletions serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,10 @@ func TestLogEntryFromLeaf(t *testing.T) {
} else if test.wantErr != "" {
t.Errorf("LogEntryFromLeaf(%d) = _, nil; want _, err containing %q", i, test.wantErr)
}
if gotCert := (got != nil && got.X509Cert != nil); gotCert != test.wantCert {
if gotCert := got != nil && got.X509Cert != nil; gotCert != test.wantCert {
t.Errorf("LogEntryFromLeaf(%d).X509Cert = %v; want %v", i, gotCert, test.wantCert)
}
if gotPrecert := (got != nil && got.Precert != nil); gotPrecert != test.wantPrecert {
if gotPrecert := got != nil && got.Precert != nil; gotPrecert != test.wantPrecert {
t.Errorf("LogEntryFromLeaf(%d).Precert = %v; want %v", i, gotPrecert, test.wantPrecert)
}
}
Expand Down
Loading

0 comments on commit add54b7

Please sign in to comment.