1984not-GmbH / molch

An implementation of the axolotl ratchet based on libsodium.
Other
23 stars 3 forks source link

foreach macro #85

Closed FSMaxB closed 7 years ago

FSMaxB commented 8 years ago

Sometimes, the same operation is done on many different inputs, in this case a foreach macro that can apply a macro in a loop would be quite useful.

Take this for example:

    buffer_destroy_from_heap_and_null(alice_private_identity);
    buffer_destroy_from_heap_and_null(alice_public_identity);
    buffer_destroy_from_heap_and_null(alice_private_ephemeral);
    buffer_destroy_from_heap_and_null(alice_public_ephemeral);
    buffer_destroy_from_heap_and_null(bob_private_identity);
    buffer_destroy_from_heap_and_null(bob_public_identity);
    buffer_destroy_from_heap_and_null(bob_private_ephemeral);
    buffer_destroy_from_heap_and_null(bob_public_ephemeral);

    buffer_destroy_from_heap_and_null(send_header_key);
    buffer_destroy_from_heap_and_null(send_message_key);
    buffer_destroy_from_heap_and_null(public_send_ephemeral);
    buffer_destroy_from_heap_and_null(current_receive_header_key);
    buffer_destroy_from_heap_and_null(next_receive_header_key);
    buffer_destroy_from_heap_and_null(receive_message_key);

This could be written as:

foreach(buffer_destroy_from_heap_and_null,
    alice_private_identity,
    alice_public_identity,
    alice_private_ephemeral,
    alice_public_ephemeral,
    bob_private_identity,
    bob_public_identity,
    bob_private_ephemeral,
    bob_public_ephemeral,

    send_header_key,
    send_message_key,
    public_send_ephemeral,
    current_receive_header_key,
    next_receive_header_key,
    receive_message_key
)

This also relates to #83.

FSMaxB commented 7 years ago

Probably not worth it.