- fix SRTP parsing

This commit is contained in:
Dmytro Bogovych 2025-09-26 14:43:46 +03:00
parent eec5aabc42
commit 3f9dbda40a
1 changed files with 30 additions and 16 deletions

View File

@ -12,27 +12,40 @@
#include <assert.h> #include <assert.h>
#include <format> #include <format>
BiMap<SrtpSuite, std::string_view> SrtpSuiteNames{{ struct SrtpSuiteAndName
{SRTP_AES_256_AUTH_80, "AES_CM_256_HMAC_SHA1_80"}, {
{SRTP_AES_128_AUTH_80, "AES_CM_128_HMAC_SHA1_80"}, SrtpSuite mSuite;
{SRTP_AES_192_AUTH_80, "AES_CM_192_HMAC_SHA1_80"}, std::string mName, mAltName;
{SRTP_AES_256_AUTH_32, "AES_CM_256_HMAC_SHA1_32"}, };
{SRTP_AES_192_AUTH_32, "AES_CM_192_HMAC_SHA1_32"},
{SRTP_AES_128_AUTH_32, "AES_CM_128_HMAC_SHA1_32"}, std::vector<SrtpSuiteAndName> SrtpSuiteList {
{SRTP_AES_128_AUTH_NULL, "AES_CM_128_NULL_AUTH"}, { SRTP_AES_256_AUTH_80, "AES_CM_256_HMAC_SHA1_80", "AES_256_CM_HMAC_SHA1_80" },
{ SRTP_AES_128_AUTH_80, "AES_CM_128_HMAC_SHA1_80", "AES_128_CM_HMAC_SHA1_80" },
{ SRTP_AES_192_AUTH_80, "AES_CM_192_HMAC_SHA1_80", "AES_192_CM_HMAC_SHA1_80" },
{ SRTP_AES_256_AUTH_32, "AES_CM_256_HMAC_SHA1_32", "AES_256_CM_HMAC_SHA1_32" },
{ SRTP_AES_192_AUTH_32, "AES_CM_192_HMAC_SHA1_32", "AES_192_CM_HMAC_SHA1_32" },
{ SRTP_AES_128_AUTH_32, "AES_CM_128_HMAC_SHA1_32", "AES_128_CM_HMAC_SHA1_32" },
{ SRTP_AES_128_AUTH_NULL, "AES_CM_128_NULL_AUTH", "AES_128_CM_NULL_AUTH"},
{ SRTP_AED_AES_256_GCM, "AEAD_AES_256_GCM"}, { SRTP_AED_AES_256_GCM, "AEAD_AES_256_GCM"},
{SRTP_AED_AES_128_GCM, "AEAD_AES_128_GCM"}}}; { SRTP_AED_AES_128_GCM, "AEAD_AES_128_GCM"}
};
extern SrtpSuite toSrtpSuite(const std::string_view& s) extern SrtpSuite toSrtpSuite(const std::string_view& s)
{ {
auto* suite = SrtpSuiteNames.find_by_value(s); for (const auto& suite: SrtpSuiteList)
return !suite ? SRTP_NONE : *suite; if (s == suite.mName || s == suite.mAltName)
return suite.mSuite;
return SRTP_NONE;
} }
extern std::string_view toString(SrtpSuite suite) extern std::string_view toString(SrtpSuite suite)
{ {
auto* s = SrtpSuiteNames.find_by_key(suite); for (const auto& item: SrtpSuiteList)
return s ? *s : std::string_view(); if (item.mSuite == suite)
return item.mName;
return {};
} }
typedef void (*set_srtp_policy_function) (srtp_crypto_policy_t*); typedef void (*set_srtp_policy_function) (srtp_crypto_policy_t*);
@ -50,9 +63,10 @@ set_srtp_policy_function findPolicyFunction(SrtpSuite suite)
case SRTP_AES_128_AUTH_NULL: return &srtp_crypto_policy_set_aes_cm_128_null_auth; break; case SRTP_AES_128_AUTH_NULL: return &srtp_crypto_policy_set_aes_cm_128_null_auth; break;
case SRTP_AED_AES_256_GCM: return &srtp_crypto_policy_set_aes_gcm_256_16_auth; break; case SRTP_AED_AES_256_GCM: return &srtp_crypto_policy_set_aes_gcm_256_16_auth; break;
case SRTP_AED_AES_128_GCM: return &srtp_crypto_policy_set_aes_gcm_128_16_auth; break; case SRTP_AED_AES_128_GCM: return &srtp_crypto_policy_set_aes_gcm_128_16_auth; break;
default: case SRTP_NONE: return nullptr;
throw std::runtime_error(std::format("SRTP suite {} is not supported", toString(suite)));
} }
return nullptr;
} }
// --- SrtpStream --- // --- SrtpStream ---