webrtc_dtls_msg (webrtc v0.1.0)

View Source

DTLS 1.2 handshake message codec (RFC 6347 §4.2.2, RFC 5246 §7.4) with the extensions WebRTC needs: supported_groups and ec_point_formats (RFC 8422), signature_algorithms, use_srtp (RFC 5764 §4.1.1), extended_master_secret (RFC 7627) and renegotiation_info (RFC 5746).

Messages are maps. decode_body/2 never raises; malformed input gives {error, decode_error} which maps to the decode_error alert.

Summary

Functions

ServerKeyExchange params for a named curve (RFC 8422 §5.4).

Decode an extension block (with its length). Raises on malformed input; callers run it under decode_body/2 style guards.

Split the payload of a handshake record into fragments.

Fragment a message so each fragment (header included) fits in Max bytes (§4.2.3).

A complete message with its 12-byte header, as it enters the handshake transcript (§4.2.6: offset 0, fragment length = length).

Types

fragment/0

-type fragment() ::
          #{type := msg_type(),
            length := non_neg_integer(),
            seq := 0..65535,
            offset := non_neg_integer(),
            data := binary()}.

msg_type/0

-type msg_type() ::
          hello_request | client_hello | server_hello | hello_verify_request | certificate |
          server_key_exchange | certificate_request | server_hello_done | certificate_verify |
          client_key_exchange | finished | new_session_ticket | encrypted_extensions | key_update |
          request_connection_id | new_connection_id | message_hash |
          0..255.

Functions

decode_body(Type, Bin)

-spec decode_body(msg_type(), binary()) -> {ok, term()} | {error, decode_error}.

ServerKeyExchange params for a named curve (RFC 8422 §5.4).

decode_extensions(Bin)

-spec decode_extensions(binary()) -> [{atom() | non_neg_integer(), term()}].

Decode an extension block (with its length). Raises on malformed input; callers run it under decode_body/2 style guards.

decode_fragment(Bin)

-spec decode_fragment(binary()) -> {ok, [fragment()]} | {error, decode_error}.

Split the payload of a handshake record into fragments.

encode_body(_, Certs)

-spec encode_body(msg_type(), map() | [binary()] | binary()) -> binary().

encode_extensions(Exts)

-spec encode_extensions([{atom() | non_neg_integer(), term()}]) -> binary().

fragments(Type, Seq, Body, Max)

-spec fragments(msg_type(), 0..65535, binary(), pos_integer()) -> [binary()].

Fragment a message so each fragment (header included) fits in Max bytes (§4.2.3).

full(Type, Seq, Body)

-spec full(msg_type(), 0..65535, binary()) -> binary().

A complete message with its 12-byte header, as it enters the handshake transcript (§4.2.6: offset 0, fragment length = length).

type_code(N)

-spec type_code(msg_type()) -> 0..255.

type_name(N)

-spec type_name(0..255) -> msg_type().