OpenSSLException.drain constructor

OpenSSLException.drain(
  1. String operation
)

Drains the current thread's error queue into an OpenSSLException.

Implementation

factory OpenSSLException.drain(String operation) {
  final codes = <int>[];
  final messages = <String>[];
  final buf = calloc<Char>(256);
  try {
    for (var i = 0; i < 32; i++) {
      final code = ssl.ERR_get_error();
      if (code == 0) break;
      codes.add(code);
      ssl.ERR_error_string_n(code, buf, 256);
      messages.add(buf.cast<Utf8>().toDartString());
    }
  } finally {
    calloc.free(buf);
  }
  return OpenSSLException(operation, codes, messages);
}