TlsConfig constructor

TlsConfig({
  1. String? certFilePath,
  2. String? keyFilePath,
  3. String? trustedCertificatesPath,
  4. SecurityContext? securityContext,
  5. bool requireClientCert = false,
})

Creates a TLS configuration.

Either securityContext or both certFilePath and keyFilePath must be provided. Throws ArgumentError if neither is set.

If requireClientCert is true, either trustedCertificatesPath or securityContext must be provided.

Implementation

TlsConfig({
  this.certFilePath,
  this.keyFilePath,
  this.trustedCertificatesPath,
  this.securityContext,
  this.requireClientCert = false,
}) {
  if (securityContext == null) {
    if (certFilePath == null || keyFilePath == null) {
      throw ArgumentError(
        'Either securityContext or both certFilePath and keyFilePath must be provided',
      );
    }
  }
  if (requireClientCert &&
      securityContext == null &&
      trustedCertificatesPath == null) {
    throw ArgumentError(
      'requireClientCert requires trustedCertificatesPath or a pre-built securityContext',
    );
  }
}