dart_tinydtls library

Dart ffi bindings to the tinydtls library.

dart_tinydtls provides a high level API for accessing tinyDTLS functionality. Both client and server APIs are exposed through the DtlsClient and DtlsServer classes. These allow users to connect to a peer or wait for incoming DtlsConnections, respectively.

tinyDTLS only supports ciphers using either a Pre-Shared Key (PSK) or an ECDSA key. These are implemented in Dart as the PskCredentials and EcdsaKeys classes. At least one of these types of credentials have to be provided, otherwise an ArgumentError is thrown.

Once the connection has been established, a DtlsConnection object is returned which can be used for sending data to the peer. The DtlsConnection also allows listening for incoming application data (in the form of Datagram objects).

Below you can see a simple example for how the DtlsClient class can be used for establishing a DtlsConnection. In this case, a PskCallback is used to pass PskCredentials, consisting of a PSK and an identity to the DtlsClient.

import 'dart:convert';
import 'dart:io';

import 'package:dart_tinydtls/dart_tinydtls.dart';

PskCredentials _pskCallback(String identityHint) {
  return PskCredentials(
      identity: "Client_identity", preSharedKey: "secretPSK");
}

Future<void> main() async {
  const address = "fe80::abcd:ef00";
  const port = 5684;

  final client = await DtlsClient.bind(InternetAddress.anyIPv6, 0);
  final connection = await client.connect(InternetAddress(address), port,
      pskCallback: _pskCallback);

  final data = utf8.encode('Hello World!');
  connection.send(data);
  client.close();
}

Classes

DtlsClient
Client for connecting to DTLS Servers and sending UDP packets with encrpyted payloads afterwards.
DtlsConnection
Represents a DTLS connection to a peer.
DtlsEvent
Describes an alert as specified by the DTLS specification or an event defined by TinyDTLS.
DtlsServer
Serves as a wrapper to tinyDTLS' server functionality.
EcdsaKeys
Class representing ECC keys (one private and two public ones).
PskCredentials
Credentials used for PSK Cipher Suites consisting of an identity and a preSharedKey.
TinyDTLS
ffi binding to the tinydtls library.

Enums

EcdsaCurve
Enumeration of the elliptic curves supported by tinyDTLS.

Typedefs

PskCallback = PskCredentials Function(Uint8List identityHint)
Function signature for a callback function for retrieving/generating PskCredentials.
PskIdentityHintCallback = Uint8List Function(InternetAddress address, int port)
Function signature for a callback function for generating a PSK identity hint for a peer, optionally based on its address and/or port.

Exceptions / Errors

DtlsException
This Exception is thrown when an error occurs within dart_tinydtls.