build static method

Implementation

static Future<PdfTrustedRootsIndex> build(
  List<PdfTrustedRootsSource> sources,
) async {
  final entries = <String, _IndexedRootSource>{};
  for (final source in sources) {
    final roots = await source.provider.getTrustedRootsDer();
    final dedupedRoots = _dedupeRoots(roots);
    final subjects = <String>{};
    for (final der in dedupedRoots) {
      try {
        final cert = X509Certificate.fromDer(der);
        final normalized = normalizeValidationName(cert.subject.toString());
        if (normalized != null) subjects.add(normalized);
      } catch (_) {
        // Ignore malformed roots in index and keep remaining valid ones.
      }
    }
    entries[source.id] = _IndexedRootSource(
      id: source.id,
      roots: dedupedRoots,
      normalizedSubjects: subjects,
    );
  }
  return PdfTrustedRootsIndex._(entries);
}