Skip to content

Commit a83ab26

Browse files
committed
Add type annotations in the C interface
1 parent afbdab4 commit a83ab26

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

include/session/config/pro.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ typedef struct pro_config {
4848
///
4949
/// Outputs:
5050
/// - `bytes32` -- The 32 byte hash calculated from the proof
51-
LIBSESSION_EXPORT bytes32 pro_proof_hash(pro_proof const* proof);
51+
LIBSESSION_EXPORT bytes32 pro_proof_hash(pro_proof const* proof) NON_NULL_ARG(1);
5252

5353
/// API: pro/pro_proof_verify_signature
5454
///
@@ -64,7 +64,8 @@ LIBSESSION_EXPORT bytes32 pro_proof_hash(pro_proof const* proof);
6464
/// Outputs:
6565
/// - `bool` -- True if verified, false otherwise
6666
LIBSESSION_EXPORT bool pro_proof_verify_signature(
67-
pro_proof const* proof, uint8_t const* verify_pubkey, size_t verify_pubkey_len);
67+
pro_proof const* proof, uint8_t const* verify_pubkey, size_t verify_pubkey_len)
68+
NON_NULL_ARG(1, 2);
6869

6970
/// API: pro/pro_proof_verify_message
7071
///
@@ -87,7 +88,7 @@ LIBSESSION_EXPORT bool pro_proof_verify_message(
8788
uint8_t const* sig,
8889
size_t sig_len,
8990
uint8_t const* msg,
90-
size_t msg_len);
91+
size_t msg_len) NON_NULL_ARG(1, 2, 4);
9192

9293
/// API: pro/pro_proof_is_active
9394
///
@@ -100,7 +101,8 @@ LIBSESSION_EXPORT bool pro_proof_verify_message(
100101
///
101102
/// Outputs:
102103
/// - `bool` -- True if expired, false otherwise
103-
LIBSESSION_EXPORT bool pro_proof_is_active(pro_proof const* proof, uint64_t unix_ts_s);
104+
LIBSESSION_EXPORT bool pro_proof_is_active(pro_proof const* proof, uint64_t unix_ts_s)
105+
NON_NULL_ARG(1);
104106

105107
/// API: pro/pro_proof_status
106108
///
@@ -133,7 +135,8 @@ LIBSESSION_EXPORT PRO_STATUS pro_proof_status(
133135
const uint8_t* verify_pubkey,
134136
size_t verify_pubkey_len,
135137
uint64_t unix_ts_s,
136-
const pro_signed_message* signed_msg);
138+
OPTIONAL const pro_signed_message* signed_msg)
139+
NON_NULL_ARG(1, 2);
137140

138141
/// API: pro/pro_proof_from_pro_backend_response
139142
///
@@ -143,7 +146,8 @@ LIBSESSION_EXPORT PRO_STATUS pro_proof_status(
143146
/// Inputs:
144147
/// - `response` -- Response from the Pro Backend containing the proof information
145148
LIBSESSION_EXPORT pro_proof pro_proof_from_pro_backend_response(
146-
struct session_pro_backend_add_pro_payment_or_get_pro_proof_response* response);
149+
struct session_pro_backend_add_pro_payment_or_get_pro_proof_response* response)
150+
NON_NULL_ARG(1);
147151

148152
/// API: pro/pro_verify
149153
///
@@ -160,7 +164,8 @@ LIBSESSION_EXPORT pro_proof pro_proof_from_pro_backend_response(
160164
/// Outputs:
161165
/// - `bytes32` -- The 32 byte hash calculated from the proof
162166
LIBSESSION_EXPORT bool pro_config_verify_signature(
163-
pro_config const* pro, uint8_t const* verify_pubkey, size_t verify_pubkey_len);
167+
pro_config const* pro, uint8_t const* verify_pubkey, size_t verify_pubkey_len)
168+
NON_NULL_ARG(1, 2);
164169

165170
#ifdef __cplusplus
166171
} // extern "C"

include/session/pro_backend.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ session_pro_backend_add_pro_payment_request_build_sigs(
177177
const uint8_t* rotating_privkey,
178178
size_t rotating_privkey_len,
179179
const uint8_t* payment_token_hash,
180-
size_t payment_token_hash_len);
180+
size_t payment_token_hash_len) NON_NULL_ARG(2, 4, 6);
181181

182182
/// API: session_pro_backend/get_pro_proof_request_build_sigs
183183
///
@@ -206,7 +206,7 @@ session_pro_backend_master_rotating_signatures session_pro_backend_get_pro_proof
206206
size_t master_privkey_len,
207207
const uint8_t* rotating_privkey,
208208
size_t rotating_privkey_len,
209-
uint64_t unix_ts_s);
209+
uint64_t unix_ts_s) NON_NULL_ARG(2, 4);
210210

211211
/// API: session_pro_backend/get_pro_payments_request_build_sig
212212
///
@@ -232,7 +232,7 @@ session_pro_backend_signature session_pro_backend_get_pro_payments_request_build
232232
const uint8_t* master_privkey,
233233
size_t master_privkey_len,
234234
uint64_t unix_ts_s,
235-
uint32_t page);
235+
uint32_t page) NON_NULL_ARG(2);
236236

237237
/// API: session_pro_backend/add_pro_payment_request_to_json
238238
///

include/session/session_protocol.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ typedef struct session_protocol_pro_features_for_msg {
141141
/// - `codepoint_count` -- Counts the number of unicode codepoints that were in the message.
142142
LIBSESSION_EXPORT
143143
session_protocol_pro_features_for_msg session_protocol_pro_features_for_utf8(
144-
char const* utf8, size_t utf8_size, PRO_EXTRA_FEATURES extra);
144+
char const* utf8, size_t utf8_size, PRO_EXTRA_FEATURES extra) NON_NULL_ARG(1);
145145

146146
/// API: session_protocol/session_protocol_get_pro_features_for_utf16
147147
///
@@ -164,7 +164,7 @@ session_protocol_pro_features_for_msg session_protocol_pro_features_for_utf8(
164164
/// - `codepoint_count` -- Counts the number of unicode codepoints that were in the message.
165165
LIBSESSION_EXPORT
166166
session_protocol_pro_features_for_msg session_protocol_pro_features_for_utf16(
167-
uint16_t const* utf16, size_t utf16_size, PRO_EXTRA_FEATURES extra);
167+
uint16_t const* utf16, size_t utf16_size, PRO_EXTRA_FEATURES extra) NON_NULL_ARG(1);
168168

169169
/// API: session_protocol_encrypt_for_1o1
170170
///
@@ -218,9 +218,9 @@ session_protocol_encrypted_for_destination session_protocol_encrypt_for_1o1(
218218
size_t ed25519_privkey_len,
219219
uint64_t sent_timestamp_ms,
220220
const bytes33* recipient_pubkey,
221-
const bytes64* pro_sig,
222-
char* error,
223-
size_t error_len);
221+
OPTIONAL const bytes64* pro_sig,
222+
OPTIONAL char* error,
223+
size_t error_len) NON_NULL_ARG(1, 3, 6);
224224

225225
/// API: session_protocol_encrypt_for_community_inbox
226226
///
@@ -279,9 +279,9 @@ session_protocol_encrypted_for_destination session_protocol_encrypt_for_communit
279279
uint64_t sent_timestamp_ms,
280280
const bytes33* recipient_pubkey,
281281
const bytes32* community_pubkey,
282-
const bytes64* pro_sig,
283-
char* error,
284-
size_t error_len);
282+
OPTIONAL const bytes64* pro_sig,
283+
OPTIONAL char* error,
284+
size_t error_len) NON_NULL_ARG(1, 3, 6, 7);
285285

286286
/// API: session_protocol_encrypt_for_group
287287
///
@@ -341,8 +341,8 @@ session_protocol_encrypted_for_destination session_protocol_encrypt_for_group(
341341
const bytes33* group_ed25519_pubkey,
342342
const bytes32* group_ed25519_privkey,
343343
const bytes64* pro_sig,
344-
char* error,
345-
size_t error_len);
344+
OPTIONAL char* error,
345+
size_t error_len) NON_NULL_ARG(1, 3, 6, 7, 8);
346346

347347
/// API: session_protocol/session_protocol_encrypt_for_destination
348348
///
@@ -391,8 +391,8 @@ session_protocol_encrypted_for_destination session_protocol_encrypt_for_destinat
391391
const void* ed25519_privkey,
392392
size_t ed25519_privkey_len,
393393
const session_protocol_destination* dest,
394-
char* error,
395-
size_t error_len);
394+
OPTIONAL char* error,
395+
size_t error_len) NON_NULL_ARG(1, 3, 5);
396396

397397
/// API: session_protocol/session_protocol_encrypt_for_destination_free
398398
///
@@ -485,8 +485,8 @@ session_protocol_decrypted_envelope session_protocol_decrypt_envelope(
485485
uint64_t unix_ts,
486486
const void* pro_backend_pubkey,
487487
size_t pro_backend_pubkey_len,
488-
char* error,
489-
size_t error_len);
488+
OPTIONAL char* error,
489+
size_t error_len) NON_NULL_ARG(1, 2, 5);
490490

491491
/// API: session_protocol/session_protocol_decrypt_envelope_free
492492
///

include/session/types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
extern "C" {
88
#endif
99

10+
#define OPTIONAL
11+
#if defined(_MSC_VER)
12+
#define NON_NULL_ARG(...)
13+
#else
14+
#define NON_NULL_ARG(...) __attribute__((nonnull(__VA_ARGS__)))
15+
#endif
16+
1017
/// C friendly buffer structure that is a pointer and length to a span of bytes.
1118
struct span_u8 {
1219
uint8_t* data;

0 commit comments

Comments
 (0)