Skip to content

Commit 814c12a

Browse files
committed
cleanup: Add dynamically derived array sizes to the API.
1 parent 226b23b commit 814c12a

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

toxav/toxav.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,12 @@ void toxav_callback_audio_bit_rate(ToxAV *av, toxav_audio_bit_rate_cb *callback,
654654
* @param u U (Chroma) plane data.
655655
* @param v V (Chroma) plane data.
656656
*/
657-
bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height, const uint8_t y[],
658-
const uint8_t u[], const uint8_t v[], Toxav_Err_Send_Frame *error);
657+
bool toxav_video_send_frame(
658+
ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height,
659+
const uint8_t y[/*! height * width */],
660+
const uint8_t u[/*! height/2 * width/2 */],
661+
const uint8_t v[/*! height/2 * width/2 */],
662+
Toxav_Err_Send_Frame *error);
659663

660664
/**
661665
* 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
737741
* @param ustride U chroma plane stride.
738742
* @param vstride V chroma plane stride.
739743
*/
740-
typedef void toxav_video_receive_frame_cb(ToxAV *av, uint32_t friend_number, uint16_t width, uint16_t height,
741-
const uint8_t y[], const uint8_t u[], const uint8_t v[], int32_t ystride, int32_t ustride, int32_t vstride,
744+
typedef void toxav_video_receive_frame_cb(
745+
ToxAV *av, uint32_t friend_number,
746+
uint16_t width, uint16_t height,
747+
const uint8_t y[/*! max(width, abs(ystride)) * height */],
748+
const uint8_t u[/*! max(width/2, abs(ustride)) * (height/2) */],
749+
const uint8_t v[/*! max(width/2, abs(vstride)) * (height/2) */],
750+
int32_t ystride, int32_t ustride, int32_t vstride,
742751
void *user_data);
743752

744753

toxencryptsave/toxencryptsave.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ bool tox_pass_key_encrypt(const Tox_Pass_Key *key, const uint8_t plaintext[], si
255255
* @return true on success.
256256
*/
257257
bool tox_pass_encrypt(const uint8_t plaintext[], size_t plaintext_len, const uint8_t passphrase[], size_t passphrase_len,
258-
uint8_t ciphertext[], Tox_Err_Encryption *error)
258+
uint8_t ciphertext[/*! plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Encryption *error)
259259
{
260260
Tox_Err_Key_Derivation err;
261261
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
338338
* @return true on success.
339339
*/
340340
bool tox_pass_decrypt(const uint8_t ciphertext[], size_t ciphertext_len, const uint8_t passphrase[],
341-
size_t passphrase_len, uint8_t plaintext[], Tox_Err_Decryption *error)
341+
size_t passphrase_len, uint8_t plaintext[/*! ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Decryption *error)
342342
{
343343
if (ciphertext_len <= TOX_PASS_ENCRYPTION_EXTRA_LENGTH) {
344344
SET_ERROR_PARAMETER(error, TOX_ERR_DECRYPTION_INVALID_LENGTH);

toxencryptsave/toxencryptsave.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ typedef enum Tox_Err_Decryption {
187187
* @return true on success.
188188
*/
189189
bool tox_pass_encrypt(const uint8_t plaintext[], size_t plaintext_len, const uint8_t passphrase[], size_t passphrase_len,
190-
uint8_t ciphertext[], Tox_Err_Encryption *error);
190+
uint8_t ciphertext[/*! plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Encryption *error);
191191

192192
/**
193193
* 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
204204
* @return true on success.
205205
*/
206206
bool tox_pass_decrypt(const uint8_t ciphertext[], size_t ciphertext_len, const uint8_t passphrase[],
207-
size_t passphrase_len, uint8_t plaintext[], Tox_Err_Decryption *error);
207+
size_t passphrase_len, uint8_t plaintext[/*! ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Decryption *error);
208208

209209

210210
/*******************************************************************************
@@ -285,7 +285,7 @@ Tox_Pass_Key *tox_pass_key_derive_with_salt(
285285
* @return true on success.
286286
*/
287287
bool tox_pass_key_encrypt(const Tox_Pass_Key *key, const uint8_t plaintext[], size_t plaintext_len,
288-
uint8_t ciphertext[], Tox_Err_Encryption *error);
288+
uint8_t ciphertext[/*! plaintext_len + TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Encryption *error);
289289

290290
/**
291291
* 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
298298
* @return true on success.
299299
*/
300300
bool tox_pass_key_decrypt(const Tox_Pass_Key *key, const uint8_t ciphertext[], size_t ciphertext_len,
301-
uint8_t plaintext[], Tox_Err_Decryption *error);
301+
uint8_t plaintext[/*! ciphertext_len - TOX_PASS_ENCRYPTION_EXTRA_LENGTH */], Tox_Err_Decryption *error);
302302

303303
typedef enum Tox_Err_Get_Salt {
304304

0 commit comments

Comments
 (0)