ExLibSRTP (ExLibSRTP v0.7.5)

Copy Markdown View Source

libsrtp bindings for Elixir.

The workflow goes as follows:

Summary

Types

Type describing possible errors that might be returned by ExLibSRTP functions.

t()

Types

libsrtp_error_t()

@type libsrtp_error_t() ::
  :fail
  | :bad_param
  | :alloc_fail
  | :dealloc_fail
  | :init_fail
  | :terminus
  | :auth_fail
  | :cipher_fail
  | :replay_fail
  | :replay_old
  | :algo_fail
  | :no_such_op
  | :no_ctx
  | :cant_check
  | :key_expired
  | :socket_err
  | :signal_err
  | :nonce_bad
  | :read_fail
  | :write_fail
  | :parse_err
  | :encode_err
  | :semaphore_err
  | :pfkey_err
  | :bad_mki
  | :pkt_idx_old

Type describing possible errors that might be returned by ExLibSRTP functions.

Meaning of these might vary depending on the function. For explanation, please refer to appropriate documentation.

This type is based on srtp_err_status_t enum.

roc_t()

@type roc_t() :: 0..4_294_967_295

ssrc_t()

@type ssrc_t() :: 0..4_294_967_295

t()

@opaque t()

Functions

add_stream(srtp, policy)

@spec add_stream(t(), policy :: ExLibSRTP.Policy.t()) :: :ok

get_stream_roc(srtp, ssrc)

@spec get_stream_roc(t(), ssrc :: ssrc_t()) ::
  {:ok, roc :: roc_t()} | {:error, libsrtp_error_t()}

Get the current roll-over counter (ROC) of a stream.

Expected errors:

  • :bad_param - no stream exists for ssrc.

is_roc(roc)

(macro)

is_ssrc(ssrc)

(macro)

new()

@spec new() :: t()

protect(srtp, unprotected, mki_index \\ nil)

@spec protect(t(), unprotected :: binary(), mki_index :: pos_integer() | nil) ::
  {:ok, protected :: binary()} | {:error, libsrtp_error_t()}

Protect RTP packet.

Most common errors:

  • :replay_fail - packet has either a duplicate sequence number or its sequence number has an old rollover counter (roc)
  • :replay_old - packet has a sequence number with current roc, but it is older than the beginning of the encryption window.
  • :bad_mki - provided MKI is not a known MKI id

Other errors indicate a failure in cryptographic mechanisms, please refer to libsrtp documentation

protect_rtcp(srtp, unprotected, mki_index \\ nil)

@spec protect_rtcp(t(), unprotected :: binary(), mki_index :: pos_integer() | nil) ::
  {:ok, protected :: binary()} | {:error, libsrtp_error_t()}

Protect RTCP packet.

All errors indicate an error in the cryptographic mechanisms.

remove_stream(srtp, ssrc)

@spec remove_stream(t(), ssrc :: ssrc_t()) :: :ok

set_stream_roc(srtp, ssrc, roc)

@spec set_stream_roc(t(), ssrc :: ssrc_t(), roc :: roc_t()) ::
  :ok | {:error, libsrtp_error_t()}

Set the roll-over counter (ROC) of an existing stream.

The stream must be added first with an :ssrc-specific policy.

Expected errors:

  • :bad_param - no stream exists for ssrc.

unprotect(srtp, protected, use_mki \\ false)

@spec unprotect(t(), protected :: binary(), use_mki :: boolean()) ::
  {:ok, unprotected :: binary()} | {:error, libsrtp_error_t()}

Unprotect RTP packet.

Most common errors:

  • :replay_fail - packet has either a duplicate sequence number or its sequence number has an old rollover counter (roc)
  • :replay_old - packet has a sequence number with current roc, but it is older than the beginning of the decryption window.
  • :auth_fail - packet has failed the message authentication check

Other errors indicate a failure in cryptographic mechanisms, please refer to libsrtp documentation

unprotect_rtcp(srtp, protected, use_mki \\ false)

@spec unprotect_rtcp(t(), protected :: binary(), use_mki :: boolean()) ::
  {:ok, unprotected :: binary()} | {:error, libsrtp_error_t()}

Unprotect RTCP packet.

Expected errors:

  • :auth_fail - SRTCP message has failed the message authentication check.
  • :replay_fail - SRTCP message is a duplicate
  • :bad_mki - provided MKI is not a known MKI id

Other errors indicate issues in the cryptographic mechanisms.

update(arg, policy)

@spec update(t(), policy :: ExLibSRTP.Policy.t()) :: :ok