mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-30 22:43:08 +03:00
Improve readability
Improve readability of the code: 1. move common code to `ssl_internal.h` as `static inline`. 2. Add comments. 3. Use local variables for extension size. 4. Change function signature, by adding buffer size and output length. 5. Take server srtp profile out of the loop. Signed-off-by: Johan Pascal <johan.pascal@belledonne-communications.com>
This commit is contained in:
@ -3257,15 +3257,16 @@ mbedtls_ssl_srtp_profile mbedtls_ssl_get_dtls_srtp_protection_profile
|
||||
*
|
||||
* \param ssl SSL context tobe used.
|
||||
* \param key Buffer to hold the generated key material.
|
||||
* \param key_len [in/out] key buffer size. outputs the actual number
|
||||
* of bytes written.
|
||||
* \param key_buffer_len Key buffer size.
|
||||
* \param olen the actual number of bytes written to key.
|
||||
*
|
||||
* \return 0 on success, #MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL if
|
||||
* the key buffer is too small to hold the generated key.
|
||||
*/
|
||||
int mbedtls_ssl_get_dtls_srtp_key_material( const mbedtls_ssl_context *ssl,
|
||||
unsigned char *key,
|
||||
size_t *key_len );
|
||||
size_t key_buffer_len,
|
||||
size_t *olen );
|
||||
|
||||
/**
|
||||
* \brief Utility function to get information on DTLS-SRTP profile.
|
||||
|
@ -1095,6 +1095,54 @@ int mbedtls_ssl_check_sig_hash( const mbedtls_ssl_context *ssl,
|
||||
mbedtls_md_type_t md );
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_SRTP)
|
||||
static inline uint16_t mbedtls_ssl_get_srtp_profile_iana_value
|
||||
( mbedtls_ssl_srtp_profile profile )
|
||||
{
|
||||
uint16_t profile_value = 0xffff;
|
||||
switch( profile )
|
||||
{
|
||||
case MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_80:
|
||||
profile_value = MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_80_IANA_VALUE;
|
||||
break;
|
||||
case MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_32:
|
||||
profile_value = MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_32_IANA_VALUE;
|
||||
break;
|
||||
case MBEDTLS_SRTP_NULL_HMAC_SHA1_80:
|
||||
profile_value = MBEDTLS_SRTP_NULL_HMAC_SHA1_80_IANA_VALUE;
|
||||
break;
|
||||
case MBEDTLS_SRTP_NULL_HMAC_SHA1_32:
|
||||
profile_value = MBEDTLS_SRTP_NULL_HMAC_SHA1_32_IANA_VALUE;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
return( profile_value );
|
||||
}
|
||||
|
||||
static inline mbedtls_ssl_srtp_profile mbedtls_ssl_get_srtp_profile_value
|
||||
( uint16_t srtp_iana_value )
|
||||
{
|
||||
mbedtls_ssl_srtp_profile profile_value = MBEDTLS_SRTP_UNSET_PROFILE;
|
||||
switch( srtp_iana_value )
|
||||
{
|
||||
case MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_80_IANA_VALUE:
|
||||
profile_value = MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_80;
|
||||
break;
|
||||
case MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_32_IANA_VALUE:
|
||||
profile_value = MBEDTLS_SRTP_AES128_CM_HMAC_SHA1_32;
|
||||
break;
|
||||
case MBEDTLS_SRTP_NULL_HMAC_SHA1_80_IANA_VALUE:
|
||||
profile_value = MBEDTLS_SRTP_NULL_HMAC_SHA1_80;
|
||||
break;
|
||||
case MBEDTLS_SRTP_NULL_HMAC_SHA1_32_IANA_VALUE:
|
||||
profile_value = MBEDTLS_SRTP_NULL_HMAC_SHA1_32;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
return( profile_value );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
static inline mbedtls_pk_context *mbedtls_ssl_own_key( mbedtls_ssl_context *ssl )
|
||||
{
|
||||
|
Reference in New Issue
Block a user