mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Refine the SRTP protect api
This commit is contained in:
parent
2989e6c9c3
commit
7f4d8a40e9
4 changed files with 41 additions and 95 deletions
|
|
@ -955,7 +955,7 @@ srs_error_t SrsSRTP::initialize(string recv_key, std::string send_key)
|
|||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsSRTP::protect_rtp(const char* plaintext, char* cipher, int& nb_cipher)
|
||||
srs_error_t SrsSRTP::protect_rtp(void* packet, int* nb_cipher)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
|
|
@ -964,17 +964,15 @@ srs_error_t SrsSRTP::protect_rtp(const char* plaintext, char* cipher, int& nb_ci
|
|||
return srs_error_new(ERROR_RTC_SRTP_PROTECT, "not ready");
|
||||
}
|
||||
|
||||
memcpy(cipher, plaintext, nb_cipher);
|
||||
|
||||
srtp_err_status_t r0 = srtp_err_status_ok;
|
||||
if ((r0 = srtp_protect(send_ctx_, cipher, &nb_cipher)) != srtp_err_status_ok) {
|
||||
if ((r0 = srtp_protect(send_ctx_, packet, nb_cipher)) != srtp_err_status_ok) {
|
||||
return srs_error_new(ERROR_RTC_SRTP_PROTECT, "rtp protect r0=%u", r0);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsSRTP::protect_rtcp(const char* plaintext, char* cipher, int& nb_cipher)
|
||||
srs_error_t SrsSRTP::protect_rtcp(void* packet, int* nb_cipher)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
|
|
@ -983,33 +981,14 @@ srs_error_t SrsSRTP::protect_rtcp(const char* plaintext, char* cipher, int& nb_c
|
|||
return srs_error_new(ERROR_RTC_SRTP_PROTECT, "not ready");
|
||||
}
|
||||
|
||||
memcpy(cipher, plaintext, nb_cipher);
|
||||
|
||||
srtp_err_status_t r0 = srtp_err_status_ok;
|
||||
if ((r0 = srtp_protect_rtcp(send_ctx_, cipher, &nb_cipher)) != srtp_err_status_ok) {
|
||||
if ((r0 = srtp_protect_rtcp(send_ctx_, packet, nb_cipher)) != srtp_err_status_ok) {
|
||||
return srs_error_new(ERROR_RTC_SRTP_PROTECT, "rtcp protect r0=%u", r0);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsSRTP::protect_rtp2(void* rtp_hdr, int* len_ptr)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// If DTLS/SRTP is not ready, fail.
|
||||
if (!send_ctx_) {
|
||||
return srs_error_new(ERROR_RTC_SRTP_PROTECT, "not ready");
|
||||
}
|
||||
|
||||
srtp_err_status_t r0 = srtp_err_status_ok;
|
||||
if ((r0 = srtp_protect(send_ctx_, rtp_hdr, len_ptr)) != srtp_err_status_ok) {
|
||||
return srs_error_new(ERROR_RTC_SRTP_PROTECT, "rtp protect r0=%u", r0);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsSRTP::unprotect_rtp(void* packet, int* nb_plaintext)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue