Commit a8c19582 authored by Ben Sartor's avatar Ben Sartor Committed by johan

added to_string and from_string for enums: MSZrtpHash, MSZrtpCipher,...

added to_string and from_string for enums: MSZrtpHash, MSZrtpCipher, MSZrtpAuthTag, MSZrtpKeyAgreement, MSZrtpSasType
Signed-off-by: johan's avatarJohan Pascal <johan.pascal@belledonne-communications.com>
parent bf7b0b02
...@@ -143,6 +143,21 @@ MS2_PUBLIC void ms_zrtp_sas_verified(MSZrtpContext* ctx); ...@@ -143,6 +143,21 @@ MS2_PUBLIC void ms_zrtp_sas_verified(MSZrtpContext* ctx);
*/ */
MS2_PUBLIC void ms_zrtp_sas_reset_verified(MSZrtpContext* ctx); MS2_PUBLIC void ms_zrtp_sas_reset_verified(MSZrtpContext* ctx);
/**
* from_string and to_string for enums: MSZrtpHash, MSZrtpCipher, MSZrtpAuthTag, MSZrtpKeyAgreement, MSZrtpSasType
*/
MS2_PUBLIC MSZrtpHash ms_zrtp_hash_from_string(const char* str);
MS2_PUBLIC const char* ms_zrtp_hash_to_string(const MSZrtpHash hash);
MS2_PUBLIC MSZrtpCipher ms_zrtp_cipher_from_string(const char* str);
MS2_PUBLIC const char* ms_zrtp_cipher_to_string(const MSZrtpCipher cipher);
MS2_PUBLIC MSZrtpAuthTag ms_zrtp_auth_tag_from_string(const char* str);
MS2_PUBLIC const char* ms_zrtp_auth_tag_to_string(const MSZrtpAuthTag authTag);
MS2_PUBLIC MSZrtpKeyAgreement ms_zrtp_key_agreement_from_string(const char* str);
MS2_PUBLIC const char* ms_zrtp_key_agreement_to_string(const MSZrtpKeyAgreement keyAgreement);
MS2_PUBLIC MSZrtpSasType ms_zrtp_sas_type_from_string(const char* str);
MS2_PUBLIC const char* ms_zrtp_sas_type_to_string(const MSZrtpSasType sasType);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -623,6 +623,107 @@ void ms_zrtp_transport_modifier_destroy(RtpTransportModifier *tp) {} ...@@ -623,6 +623,107 @@ void ms_zrtp_transport_modifier_destroy(RtpTransportModifier *tp) {}
void ms_zrtp_set_stream_sessions(MSZrtpContext *zrtp_context, MSMediaStreamSessions *stream_sessions) {} void ms_zrtp_set_stream_sessions(MSZrtpContext *zrtp_context, MSMediaStreamSessions *stream_sessions) {}
#endif #endif
#define STRING_COMPARE_RETURN(string, value)\
if (strcmp(string,#value) == 0) return value
#define CASE_RETURN_STRING(value)\
case value: return #value;
#define SWITCH_CRYPTO_ALGO(value, cases)\
switch(value) {\
cases\
}\
return "<NULL>";
MS2_PUBLIC MSZrtpHash ms_zrtp_hash_from_string(const char* str) {
STRING_COMPARE_RETURN(str, MS_ZRTP_HASH_S256);
STRING_COMPARE_RETURN(str, MS_ZRTP_HASH_S384);
STRING_COMPARE_RETURN(str, MS_ZRTP_HASH_N256);
STRING_COMPARE_RETURN(str, MS_ZRTP_HASH_N384);
return MS_ZRTP_HASH_INVALID;
}
MS2_PUBLIC const char* ms_zrtp_hash_to_string(const MSZrtpHash hash) {
SWITCH_CRYPTO_ALGO(hash,\
CASE_RETURN_STRING(MS_ZRTP_HASH_INVALID);\
CASE_RETURN_STRING(MS_ZRTP_HASH_S256);\
CASE_RETURN_STRING(MS_ZRTP_HASH_S384);\
CASE_RETURN_STRING(MS_ZRTP_HASH_N256);\
CASE_RETURN_STRING(MS_ZRTP_HASH_N384);\
);
}
MS2_PUBLIC MSZrtpCipher ms_zrtp_cipher_from_string(const char* str) {
STRING_COMPARE_RETURN(str, MS_ZRTP_CIPHER_AES1);
STRING_COMPARE_RETURN(str, MS_ZRTP_CIPHER_AES2);
STRING_COMPARE_RETURN(str, MS_ZRTP_CIPHER_AES3);
STRING_COMPARE_RETURN(str, MS_ZRTP_CIPHER_2FS1);
STRING_COMPARE_RETURN(str, MS_ZRTP_CIPHER_2FS2);
STRING_COMPARE_RETURN(str, MS_ZRTP_CIPHER_2FS3);
return MS_ZRTP_CIPHER_INVALID;
}
MS2_PUBLIC const char* ms_zrtp_cipher_to_string(const MSZrtpCipher cipher) {
SWITCH_CRYPTO_ALGO(cipher,\
CASE_RETURN_STRING(MS_ZRTP_CIPHER_INVALID);\
CASE_RETURN_STRING(MS_ZRTP_CIPHER_AES1);\
CASE_RETURN_STRING(MS_ZRTP_CIPHER_AES2);\
CASE_RETURN_STRING(MS_ZRTP_CIPHER_AES3);\
CASE_RETURN_STRING(MS_ZRTP_CIPHER_2FS1);\
CASE_RETURN_STRING(MS_ZRTP_CIPHER_2FS2);\
CASE_RETURN_STRING(MS_ZRTP_CIPHER_2FS3);\
);
}
MS2_PUBLIC MSZrtpAuthTag ms_zrtp_auth_tag_from_string(const char* str) {
STRING_COMPARE_RETURN(str, MS_ZRTP_AUTHTAG_HS32);
STRING_COMPARE_RETURN(str, MS_ZRTP_AUTHTAG_HS80);
STRING_COMPARE_RETURN(str, MS_ZRTP_AUTHTAG_SK32);
STRING_COMPARE_RETURN(str, MS_ZRTP_AUTHTAG_SK64);
return MS_ZRTP_AUTHTAG_INVALID;
}
MS2_PUBLIC const char* ms_zrtp_auth_tag_to_string(const MSZrtpAuthTag authTag) {
SWITCH_CRYPTO_ALGO(authTag,\
CASE_RETURN_STRING(MS_ZRTP_AUTHTAG_INVALID);\
CASE_RETURN_STRING(MS_ZRTP_AUTHTAG_HS32);\
CASE_RETURN_STRING(MS_ZRTP_AUTHTAG_HS80);\
CASE_RETURN_STRING(MS_ZRTP_AUTHTAG_SK32);\
CASE_RETURN_STRING(MS_ZRTP_AUTHTAG_SK64);\
);
}
MSZrtpKeyAgreement ms_zrtp_key_agreement_from_string(const char* str) {
STRING_COMPARE_RETURN(str, MS_ZRTP_KEY_AGREEMENT_DH2K);
STRING_COMPARE_RETURN(str, MS_ZRTP_KEY_AGREEMENT_DH3K);
STRING_COMPARE_RETURN(str, MS_ZRTP_KEY_AGREEMENT_EC25);
STRING_COMPARE_RETURN(str, MS_ZRTP_KEY_AGREEMENT_EC38);
STRING_COMPARE_RETURN(str, MS_ZRTP_KEY_AGREEMENT_EC52);
return MS_ZRTP_KEY_AGREEMENT_INVALID;
}
const char* ms_zrtp_key_agreement_to_string(const MSZrtpKeyAgreement keyAgreement) {
SWITCH_CRYPTO_ALGO(keyAgreement,\
CASE_RETURN_STRING(MS_ZRTP_KEY_AGREEMENT_INVALID);\
CASE_RETURN_STRING(MS_ZRTP_KEY_AGREEMENT_DH2K);\
CASE_RETURN_STRING(MS_ZRTP_KEY_AGREEMENT_DH3K);\
CASE_RETURN_STRING(MS_ZRTP_KEY_AGREEMENT_EC25);\
CASE_RETURN_STRING(MS_ZRTP_KEY_AGREEMENT_EC38);\
CASE_RETURN_STRING(MS_ZRTP_KEY_AGREEMENT_EC52);\
);
}
MS2_PUBLIC MSZrtpSasType ms_zrtp_sas_type_from_string(const char* str) {
STRING_COMPARE_RETURN(str, MS_ZRTP_SAS_B32);
STRING_COMPARE_RETURN(str, MS_ZRTP_SAS_B256);
return MS_ZRTP_SAS_INVALID;
}
MS2_PUBLIC const char* ms_zrtp_sas_type_to_string(const MSZrtpSasType sasType) {
SWITCH_CRYPTO_ALGO(sasType,\
CASE_RETURN_STRING(MS_ZRTP_SAS_INVALID);\
CASE_RETURN_STRING(MS_ZRTP_SAS_B32);\
CASE_RETURN_STRING(MS_ZRTP_SAS_B256);\
);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment