Search results

There are no results.

std.net.tls.ServerConfig

class pub ServerConfig

A type storing the configuration details for TLS servers.

To configure a Client, use ClientConfig instead.

Creating a ServerConfig is potentially expensive, depending on the certificate and private key that are used. As such, it's recommended to only create a ServerConfig once and use ServerConfig.clone to clone it whenever necessary, as cloning a ServerConfig is cheap.

Static methods

new

Show source code
Hide source code
fn pub static new(
  certificate: ref Certificate,
  key: ref PrivateKey,
) -> Result[ServerConfig, ServerConfigError] {
  match inko_tls_server_config_new(certificate.bytes, key.bytes) {
    case { @tag = 0, @value = v } -> {
      Result.Ok(ServerConfig(v as Pointer[UInt8]))
    }
    case { @value = e } if e as Int == INVALID_CERT -> {
      Result.Error(ServerConfigError.InvalidCertificate)
    }
    case _ -> Result.Error(ServerConfigError.InvalidPrivateKey)
  }
}
fn pub static new(certificate: ref Certificate, key: ref PrivateKey) -> Result[ServerConfig, ServerConfigError]

Returns a new ClientConfig using the specified PEM encoded X.509 certificate and private key.

Errors

A ServerConfigError is returned if any of the following is true:

  • The certificate is invalid
  • The private key is invalid

Examples

import std.net.tls (ServerConfig)
import std.crypto.x509 (Certificate, PrivateKey)

let cert = Certificate.new(ByteArray.from_array([1, 2, 3]))
let key = PrivateKey.new(ByteArray.from_array([4, 5, 6]))

ServerConfig.new(cert, key).or_panic('failed to create the configuration')

Instance methods

clone

Show source code
Hide source code
fn pub clone -> ServerConfig {
  ServerConfig(inko_tls_server_config_clone(@raw))
}
fn pub clone -> ServerConfig

Creates a clone of self.

Implemented traits

std.clone.

Clone

impl Clone[ServerConfig] for ServerConfig
std.drop.

Drop

impl Drop for ServerConfig