W3cubDocs

/Dart 2

secure method

Future<RawSecureSocket> secure (RawSocket socket, { StreamSubscription<RawSocketEvent> subscription, dynamic host, SecurityContext context, bool onBadCertificate(X509Certificate certificate), List<String> supportedProtocols })

Takes an already connected socket and starts client side TLS handshake to make the communication secure. When the returned future completes the RawSecureSocket has completed the TLS handshake. Using this function requires that the other end of the connection is prepared for TLS handshake.

If the socket already has a subscription, pass the existing subscription in the subscription parameter. The secure operation will take over the subscription by replacing the handlers with it own secure processing. The caller must not touch this subscription anymore. Passing a paused subscription is an error.

If the host argument is passed it will be used as the host name for the TLS handshake. If host is not passed the host name from the socket will be used. The host can be either a String or an InternetAddress.

Calling this function will not cause a DNS host lookup. If the host passed is a String the InternetAddress for the resulting SecureSocket will have this passed in host as its host value and the internet address of the already connected socket as its address value.

See connect for more information on the arguments.

Implementation

static Future<RawSecureSocket> secure(RawSocket socket,
    {StreamSubscription<RawSocketEvent> subscription,
    host,
    SecurityContext context,
    bool onBadCertificate(X509Certificate certificate),
    List<String> supportedProtocols}) {
  socket.readEventsEnabled = false;
  socket.writeEventsEnabled = false;
  return _RawSecureSocket.connect(
      host != null ? host : socket.address.host, socket.port,
      is_server: false,
      socket: socket,
      subscription: subscription,
      context: context,
      onBadCertificate: onBadCertificate,
      supportedProtocols: supportedProtocols);
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-io/RawSecureSocket/secure.html