verifyChain method

List<X509> verifyChain(
  1. List<X509> chain,
  2. List<X509> trusted
)

Verify the full certification chain and returns it

Implementation

List<X509> verifyChain(
  List<X509> chain,
  List<X509> trusted,
) {
  if (trusted.contains(this)) {
    return [this];
  }

  for (final intermediate in chain) {
    try {
      verify(intermediate);
      return [
        this,
        ...intermediate.verifyChain(
          chain.where((e) => e != intermediate).toList(),
          trusted,
        ),
      ];
      // ignore: empty_catches
    } catch (e) {}
  }

  for (final ca in trusted) {
    try {
      verify(ca);
      return [this, ca];
      // ignore: empty_catches
    } catch (e) {}
  }

  throw Exception('No trusted certification chain found');
}