func MapPairs()

in certdataDiffCCADB/utils/pair.go [26:63]


func MapPairs(cd, ccadb []*Entry) (pairs []Pair, unmatchedT []*Entry, unmatchedUT []*Entry) {
	idMap := make(map[string]*Entry) // DN || serial
	ftocd := make(map[string]*Entry) // fingerprint
	for _, e := range cd {
		idMap[e.UniqueID()] = e
		ftocd[e.Fingerprint] = e
	}
	var pair Pair
	var match *Entry
	var ok bool
	for _, e := range ccadb {
		id := e.UniqueID()
		if match, ok = idMap[id]; ok {
			pair = NewPair(match, e)
		} else if match, ok = ftocd[e.Fingerprint]; ok {
			pair = NewPair(match, e)
		} else {
			if !(e.TrustWeb || e.TrustEmail) {
				unmatchedUT = append(unmatchedUT, e)
			} else {
				unmatchedT = append(unmatchedT, e)
			}
			continue
		}
		pairs = append(pairs, pair)
		// Avoid matching duplicates
		delete(idMap, match.UniqueID())
		delete(ftocd, match.Fingerprint)
	}
	for _, e := range idMap {
		if !(e.TrustWeb || e.TrustEmail) {
			unmatchedUT = append(unmatchedUT, e)
		} else {
			unmatchedT = append(unmatchedT, e)
		}
	}
	return
}