From 814c12a6f414b8631fe19f12525994a5d3235449 Mon Sep 17 00:00:00 2001 From: iphydf Date: Fri, 5 Jan 2024 21:05:26 +0000 Subject: [PATCH] cleanup: Add dynamically derived array sizes to the API. --- toxav/toxav.h | 17 +++++++++++++---- toxencryptsave/toxencryptsave.c | 4 ++-- toxencryptsave/toxencryptsave.h | 8 ++++---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/toxav/toxav.h b/toxav/toxav.h index e34dc184..ff65c3fa 100644 --- a/toxav/toxav.h +++ b/toxav/toxav.h @@ -654,8 +654,12 @@ void toxav_callback_audio_bit_rate(ToxAV *av, toxav_audio_bit_rate_cb *callback, * @param u U (Chroma) plane data. * @param v V (Chroma) plane data. */ -bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height, const uint8_t y[], - const uint8_t u[], const uint8_t v[], Toxav_Err_Send_Frame *error); +bool toxav_video_send_frame( + ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height, + const uint8_t y[/*! height * width */], + const uint8_t u[/*! height/2 * width/2 */], + const uint8_t v[/*! height/2 * width/2 */], + Toxav_Err_Send_Frame *error); /** * Set the bit rate to be used in subsequent video frames. @@ -737,8 +741,13 @@ void toxav_callback_audio_receive_frame(ToxAV *av, toxav_audio_receive_frame_cb * @param ustride U chroma plane stride. * @param vstride V chroma plane stride. */ -typedef void toxav_video_receive_frame_cb(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height, - const uint8_t y[], const uint8_t u[], const uint8_t v[], int32_t ystride, int32_t ustride, int32_t vstride, +typedef void toxav_video_receive_frame_cb( + ToxAV *av, uint32_t friend_number, + uint16_t width, uint16_t height, + const uint8_t y[/*! max(width, abs(ystride)) * height */], + const uint8_t u[/*! max(width/2, abs(ustride)) * (height/2) */], + const uint8_t v[/*! max(width/2, abs(vstride)) * (height/2) */], + int32_t ystride, int32_t ustride, int32_t vstride, void *user_data); diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index e1e0f4a4..a8110fb9 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c @@ -255,7 +255,7 @@ bool tox_pass_key_encrypt(const Tox_Pass_Key *key, const uint8_t plaintext[], si * @return true on success. */ bool tox_pass_encrypt(const uint8_t plaintext[], size_t plaintext_len, const uint8_t passphrase[], size_t passphrase_len, - uint8_t ciphertext[], Tox_Err_Encryption *error) + uint8_t ciphertext[/*! plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Encryption *error) { Tox_Err_Key_Derivation err; Tox_Pass_Key *key = tox_pass_key_derive(passphrase, passphrase_len, &err); @@ -338,7 +338,7 @@ bool tox_pass_key_decrypt(const Tox_Pass_Key *key, const uint8_t ciphertext[], s * @return true on success. */ bool tox_pass_decrypt(const uint8_t ciphertext[], size_t ciphertext_len, const uint8_t passphrase[], - size_t passphrase_len, uint8_t plaintext[], Tox_Err_Decryption *error) + size_t passphrase_len, uint8_t plaintext[/*! ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Decryption *error) { if (ciphertext_len <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH) { SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_INVALID_LENGTH); diff --git a/toxencryptsave/toxencryptsave.h b/toxencryptsave/toxencryptsave.h index c173dce5..4bc532ad 100644 --- a/toxencryptsave/toxencryptsave.h +++ b/toxencryptsave/toxencryptsave.h @@ -187,7 +187,7 @@ typedef enum Tox_Err_Decryption { * @return true on success. */ bool tox_pass_encrypt(const uint8_t plaintext[], size_t plaintext_len, const uint8_t passphrase[], size_t passphrase_len, - uint8_t ciphertext[], Tox_Err_Encryption *error); + uint8_t ciphertext[/*! plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Encryption *error); /** * Decrypts the given data with the given passphrase. @@ -204,7 +204,7 @@ bool tox_pass_encrypt(const uint8_t plaintext[], size_t plaintext_len, const uin * @return true on success. */ bool tox_pass_decrypt(const uint8_t ciphertext[], size_t ciphertext_len, const uint8_t passphrase[], - size_t passphrase_len, uint8_t plaintext[], Tox_Err_Decryption *error); + size_t passphrase_len, uint8_t plaintext[/*! ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Decryption *error); /******************************************************************************* @@ -285,7 +285,7 @@ Tox_Pass_Key *tox_pass_key_derive_with_salt( * @return true on success. */ bool tox_pass_key_encrypt(const Tox_Pass_Key *key, const uint8_t plaintext[], size_t plaintext_len, - uint8_t ciphertext[], Tox_Err_Encryption *error); + uint8_t ciphertext[/*! plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Encryption *error); /** * This is the inverse of tox_pass_key_encrypt, also using only keys produced by @@ -298,7 +298,7 @@ bool tox_pass_key_encrypt(const Tox_Pass_Key *key, const uint8_t plaintext[], si * @return true on success. */ bool tox_pass_key_decrypt(const Tox_Pass_Key *key, const uint8_t ciphertext[], size_t ciphertext_len, - uint8_t plaintext[], Tox_Err_Decryption *error); + uint8_t plaintext[/*! ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Decryption *error); typedef enum Tox_Err_Get_Salt {