@@ -12,6 +12,42 @@ defmodule ExLibSRTP do
1212
1313 alias ExLibSRTP . { Native , Policy }
1414
15+ @ typedoc """
16+ Type describing possible errors that might be returned by ExLibSRTP functions.
17+
18+ Meaning of these might vary depending on the function. For explanation, please refer to
19+ appropriate documentation.
20+
21+ This type is based on [`srtp_err_status_t` enum](https://github.com/cisco/libsrtp/blob/004b7bb85caf4f52a7cc8a7aad94d9d1706e8b6d/include/srtp.h#L164).
22+ """
23+ @ type libsrtp_error_t ( ) ::
24+ :fail
25+ | :bad_param
26+ | :alloc_fail
27+ | :dealloc_fail
28+ | :init_fail
29+ | :terminus
30+ | :auth_fail
31+ | :cipher_fail
32+ | :replay_fail
33+ | :replay_old
34+ | :algo_fail
35+ | :no_such_op
36+ | :no_ctx
37+ | :cant_check
38+ | :key_expired
39+ | :socket_err
40+ | :signal_err
41+ | :nonce_bad
42+ | :read_fail
43+ | :write_fail
44+ | :parse_err
45+ | :encode_err
46+ | :semaphore_err
47+ | :pfkey_err
48+ | :bad_mki
49+ | :pkt_idx_old
50+
1551 @ opaque t :: { __MODULE__ , native :: reference }
1652
1753 @ type ssrc_t :: 0 .. 4_294_967_295
@@ -72,8 +108,18 @@ defmodule ExLibSRTP do
72108 )
73109 end
74110
111+ @ doc """
112+ Protect RTP packet.
113+
114+ Most common errors:
115+ - `:replay_fail` - packet has either a duplicate sequence number or its sequence number has an old rollover counter (roc)
116+ - `:replay_old` - packet has a sequence number with current roc, but it is older than the beginning of the encryption window.
117+ - `:bad_mki` - provided MKI is not a known MKI id
118+
119+ Other errors indicate a failure in cryptographic mechanisms, please refer to [libsrtp documentation](https://github.com/cisco/libsrtp)
120+ """
75121 @ spec protect ( t ( ) , unprotected :: binary ( ) , mki_index :: pos_integer ( ) | nil ) ::
76- { :ok , protected :: binary ( ) }
122+ { :ok , protected :: binary ( ) } | { :error , libsrtp_error_t ( ) }
77123 def protect ( srtp , unprotected , mki_index \\ nil )
78124
79125 def protect ( ref ( native ) , unprotected , nil ) do
@@ -84,8 +130,13 @@ defmodule ExLibSRTP do
84130 Native . protect ( native , :rtp , unprotected , true , mki_index )
85131 end
86132
133+ @ doc """
134+ Protect RTCP packet.
135+
136+ All errors indicate an error in the cryptographic mechanisms.
137+ """
87138 @ spec protect_rtcp ( t ( ) , unprotected :: binary ( ) , mki_index :: pos_integer ( ) | nil ) ::
88- { :ok , protected :: binary ( ) }
139+ { :ok , protected :: binary ( ) } | { :error , libsrtp_error_t ( ) }
89140 def protect_rtcp ( srtp , unprotected , mki_index \\ nil )
90141
91142 def protect_rtcp ( ref ( native ) , unprotected , nil ) do
@@ -96,14 +147,34 @@ defmodule ExLibSRTP do
96147 Native . protect ( native , :rtcp , unprotected , true , mki_index )
97148 end
98149
150+ @ doc """
151+ Unprotect RTP packet.
152+
153+ Most common errors:
154+ - `:replay_fail` - packet has either a duplicate sequence number or its sequence number has an old rollover counter (roc)
155+ - `:replay_old` - packet has a sequence number with current roc, but it is older than the beginning of the decryption window.
156+ - `:auth_fail` - packet has failed the message authentication check
157+
158+ Other errors indicate a failure in cryptographic mechanisms, please refer to [libsrtp documentation](https://github.com/cisco/libsrtp)
159+ """
99160 @ spec unprotect ( t ( ) , protected :: binary ( ) , use_mki :: boolean ( ) ) ::
100- { :ok , unprotected :: binary ( ) } | { :error , :auth_fail | :reply_fail | :bad_mki }
161+ { :ok , unprotected :: binary ( ) } | { :error , libsrtp_error_t ( ) }
101162 def unprotect ( ref ( native ) = _srtp , protected , use_mki \\ false ) do
102163 Native . unprotect ( native , :rtp , protected , use_mki )
103164 end
104165
166+ @ doc """
167+ Unprotect RTCP packet.
168+
169+ Expected errors:
170+ - `:auth_fail` - SRTCP message has failed the message authentication check.
171+ - `:replay_fail` - SRTCP message is a duplicate
172+ - `:bad_mki` - provided MKI is not a known MKI id
173+
174+ Other errors indicate issues in the cryptographic mechanisms.
175+ """
105176 @ spec unprotect_rtcp ( t ( ) , protected :: binary ( ) , use_mki :: boolean ( ) ) ::
106- { :ok , unprotected :: binary ( ) } | { :error , :auth_fail | :reply_fail | :bad_mki }
177+ { :ok , unprotected :: binary ( ) } | { :error , libsrtp_error_t ( ) }
107178 def unprotect_rtcp ( ref ( native ) = _srtp , protected , use_mki \\ false ) do
108179 Native . unprotect ( native , :rtcp , protected , use_mki )
109180 end
0 commit comments