@@ -16,61 +16,71 @@ import (
1616 "golang.org/x/net/context"
1717)
1818
19- // Clients wishing to implement their own Matchers should implement this interface:
19+ // Matcher describes how to match certificates and precertificates; clients should implement this interface
20+ // to perform their own match criteria.
2021type Matcher interface {
2122 // CertificateMatches is called by the scanner for each X509 Certificate found in the log.
22- // The implementation should return | true| if the passed Certificate is interesting, and | false| otherwise.
23+ // The implementation should return true if the passed Certificate is interesting, and false otherwise.
2324 CertificateMatches (* x509.Certificate ) bool
2425
2526 // PrecertificateMatches is called by the scanner for each CT Precertificate found in the log.
26- // The implementation should return | true| if the passed Precertificate is interesting, and | false| otherwise.
27+ // The implementation should return true if the passed Precertificate is interesting, and false otherwise.
2728 PrecertificateMatches (* ct.Precertificate ) bool
2829}
2930
3031// MatchAll is a Matcher which will match every possible Certificate and Precertificate.
3132type MatchAll struct {}
3233
34+ // CertificateMatches returns true if the given cert should match; in this case, always.
3335func (m MatchAll ) CertificateMatches (_ * x509.Certificate ) bool {
3436 return true
3537}
3638
39+ // PrecertificateMatches returns true if the given precert should match, in this case, always.
3740func (m MatchAll ) PrecertificateMatches (_ * ct.Precertificate ) bool {
3841 return true
3942}
4043
4144// MatchNone is a Matcher which will never match any Certificate or Precertificate.
4245type MatchNone struct {}
4346
47+ // CertificateMatches returns true if the given cert should match; in this case, never.
4448func (m MatchNone ) CertificateMatches (_ * x509.Certificate ) bool {
4549 return false
4650}
4751
52+ // PrecertificateMatches returns true if the given cert should match; in this case, never.
4853func (m MatchNone ) PrecertificateMatches (_ * ct.Precertificate ) bool {
4954 return false
5055}
5156
57+ // MatchSerialNumber performs a match for a specific serial number.
5258type MatchSerialNumber struct {
5359 SerialNumber big.Int
5460}
5561
62+ // CertificateMatches returns true if the given cert should match; in this
63+ // case, only if the serial number matches.
5664func (m MatchSerialNumber ) CertificateMatches (c * x509.Certificate ) bool {
5765 return c .SerialNumber .String () == m .SerialNumber .String ()
5866}
5967
68+ // PrecertificateMatches returns true if the given cert should match; in this
69+ // case, only if the serial number matches.
6070func (m MatchSerialNumber ) PrecertificateMatches (p * ct.Precertificate ) bool {
6171 return p .TBSCertificate .SerialNumber .String () == m .SerialNumber .String ()
6272}
6373
64- // MatchSubjectRegex is a Matcher which will use | CertificateSubjectRegex| and | PrecertificateSubjectRegex|
74+ // MatchSubjectRegex is a Matcher which will use CertificateSubjectRegex and PrecertificateSubjectRegex
6575// to determine whether Certificates and Precertificates are interesting.
66- // The two regexes are tested against Subject Common Name as well as all
76+ // The two regexes are tested against Subject CN ( Common Name) as well as all
6777// Subject Alternative Names
6878type MatchSubjectRegex struct {
6979 CertificateSubjectRegex * regexp.Regexp
7080 PrecertificateSubjectRegex * regexp.Regexp
7181}
7282
73- // Returns true if either CN or any SAN of |c| matches | CertificateSubjectRegex| .
83+ // CertificateMatches returns true if either CN or any SAN of c matches m. CertificateSubjectRegex.
7484func (m MatchSubjectRegex ) CertificateMatches (c * x509.Certificate ) bool {
7585 if m .CertificateSubjectRegex .FindStringIndex (c .Subject .CommonName ) != nil {
7686 return true
@@ -83,7 +93,7 @@ func (m MatchSubjectRegex) CertificateMatches(c *x509.Certificate) bool {
8393 return false
8494}
8595
86- // Returns true if either CN or any SAN of |p| matches |PrecertificatesubjectRegex| .
96+ // PrecertificateMatches returns true if either CN or any SAN of p matches m.PrecertificateSubjectRegex .
8797func (m MatchSubjectRegex ) PrecertificateMatches (p * ct.Precertificate ) bool {
8898 if m .PrecertificateSubjectRegex .FindStringIndex (p .TBSCertificate .Subject .CommonName ) != nil {
8999 return true
@@ -96,16 +106,18 @@ func (m MatchSubjectRegex) PrecertificateMatches(p *ct.Precertificate) bool {
96106 return false
97107}
98108
99- // Matches on issuer cn by regex
109+ // MatchIssuerRegex matches on issuer CN (common name) by regex
100110type MatchIssuerRegex struct {
101111 CertificateIssuerRegex * regexp.Regexp
102112 PrecertificateIssuerRegex * regexp.Regexp
103113}
104114
115+ // CertificateMatches returns true if the given cert's CN matches.
105116func (m MatchIssuerRegex ) CertificateMatches (c * x509.Certificate ) bool {
106117 return m .CertificateIssuerRegex .FindStringIndex (c .Issuer .CommonName ) != nil
107118}
108119
120+ // PrecertificateMatches returns true if the given precert's CN matches.
109121func (m MatchIssuerRegex ) PrecertificateMatches (p * ct.Precertificate ) bool {
110122 return m .PrecertificateIssuerRegex .FindStringIndex (p .TBSCertificate .Issuer .CommonName ) != nil
111123}
@@ -135,7 +147,7 @@ type ScannerOptions struct {
135147 Quiet bool
136148}
137149
138- // Creates a new ScannerOptions struct with sensible defaults
150+ // DefaultScannerOptions creates a new ScannerOptions struct with sensible defaults.
139151func DefaultScannerOptions () * ScannerOptions {
140152 return & ScannerOptions {
141153 Matcher : & MatchAll {},
@@ -189,7 +201,7 @@ type fetchRange struct {
189201// nil.
190202// Fatal errors will be logged, unparsableEntires will be incremented, and the
191203// fatal error itself will be returned.
192- // When | err| is nil, this method does nothing.
204+ // When err is nil, this method does nothing.
193205func (s * Scanner ) handleParseEntryError (err error , entryType ct.LogEntryType , index int64 ) error {
194206 if err == nil {
195207 // No error to handle
@@ -208,7 +220,7 @@ func (s *Scanner) handleParseEntryError(err error, entryType ct.LogEntryType, in
208220 return nil
209221}
210222
211- // Processes the given | entry| in the specified log.
223+ // Processes the given entry in the specified log.
212224func (s * Scanner ) processEntry (entry ct.LogEntry , foundCert func (* ct.LogEntry ), foundPrecert func (* ct.LogEntry )) {
213225 atomic .AddInt64 (& s .certsProcessed , 1 )
214226 switch entry .Leaf .TimestampedEntry .EntryType {
@@ -245,8 +257,8 @@ func (s *Scanner) processEntry(entry ct.LogEntry, foundCert func(*ct.LogEntry),
245257}
246258
247259// Worker function to match certs.
248- // Accepts MatcherJobs over the | entries| channel, and processes them.
249- // Returns true over the | done| channel when the | entries| channel is closed.
260+ // Accepts MatcherJobs over the entries channel, and processes them.
261+ // Returns true over the done channel when the entries channel is closed.
250262func (s * Scanner ) matcherJob (id int , entries <- chan matcherJob , foundCert func (* ct.LogEntry ), foundPrecert func (* ct.LogEntry ), wg * sync.WaitGroup ) {
251263 for e := range entries {
252264 s .processEntry (e .entry , foundCert , foundPrecert )
@@ -256,11 +268,11 @@ func (s *Scanner) matcherJob(id int, entries <-chan matcherJob, foundCert func(*
256268}
257269
258270// Worker function for fetcher jobs.
259- // Accepts cert ranges to fetch over the | ranges| channel, and if the fetch is
271+ // Accepts cert ranges to fetch over the ranges channel, and if the fetch is
260272// successful sends the individual LeafInputs out (as MatcherJobs) into the
261- // | entries| channel for the matchers to chew on.
273+ // entries channel for the matchers to chew on.
262274// Will retry failed attempts to retrieve ranges indefinitely.
263- // Sends true over the | done| channel when the | ranges| channel is closed.
275+ // Sends true over the done channel when the ranges channel is closed.
264276func (s * Scanner ) fetcherJob (id int , ranges <- chan fetchRange , entries chan <- matcherJob , wg * sync.WaitGroup ) {
265277 for r := range ranges {
266278 success := false
@@ -288,25 +300,21 @@ func (s *Scanner) fetcherJob(id int, ranges <-chan fetchRange, entries chan<- ma
288300 wg .Done ()
289301}
290302
291- // Returns the smaller of |a| and |b|
292303func min (a int64 , b int64 ) int64 {
293304 if a < b {
294305 return a
295- } else {
296- return b
297306 }
307+ return b
298308}
299309
300- // Returns the larger of |a| and |b|
301310func max (a int64 , b int64 ) int64 {
302311 if a > b {
303312 return a
304- } else {
305- return b
306313 }
314+ return b
307315}
308316
309- // Pretty prints the passed in number of | seconds| into a more human readable
317+ // Pretty prints the passed in number of seconds into a more human readable
310318// string.
311319func humanTime (seconds int ) string {
312320 nanos := time .Duration (seconds ) * time .Second
@@ -328,10 +336,10 @@ func humanTime(seconds int) string {
328336 return s
329337}
330338
331- // Performs a scan against the Log.
332- // For each x509 certificate found, | foundCert| will be called with the
339+ // Scan performs a scan against the Log.
340+ // For each x509 certificate found, foundCert will be called with the
333341// index of the entry and certificate itself as arguments. For each precert
334- // found, | foundPrecert| will be called with the index of the entry and the raw
342+ // found, foundPrecert will be called with the index of the entry and the raw
335343// precert string as the arguments.
336344//
337345// This method blocks until the scan is complete.
@@ -397,8 +405,8 @@ func (s *Scanner) Scan(foundCert func(*ct.LogEntry),
397405 return nil
398406}
399407
400- // Creates a new Scanner instance using | client| to talk to the log, and taking
401- // configuration options from | opts| .
408+ // NewScanner creates a new Scanner instance using client to talk to the log,
409+ // taking configuration options from opts.
402410func NewScanner (client * client.LogClient , opts ScannerOptions ) * Scanner {
403411 var scanner Scanner
404412 scanner .logClient = client
0 commit comments