getOrCreateStore method

X509Store getOrCreateStore(
  1. String storeKey,
  2. List<Uint8List> rootsDer
)

Returns a cached X509_STORE for a truststore fingerprint key.

Implementation

X509Store getOrCreateStore(String storeKey, List<Uint8List> rootsDer) {
  final cached = _storeCache[storeKey];
  if (cached != null) {
    return cached;
  }

  final store = X509Store.create(this);
  for (final rootDer in rootsDer) {
    final certPtr = getOrCreateParsedX509(rootDer);
    try {
      final rc = bindings.X509_STORE_add_cert(store.handle, certPtr);
      if (rc != 1) {
        throw OpenSslException('X509_STORE_add_cert failed for cached root');
      }
    } finally {
      bindings.X509_free(certPtr);
    }
  }

  _storeCache[storeKey] = store;
  return store;
}