Hi,
i've got a c declaration that i like to wrap:
void crypto_ed25519_sign(u8 signature[64],
const u8 secret_key[32],
const u8 *message,
size_t message_size)
c2nim produces this:
proc crypto_ed25519_sign*(signature: array[64, uint8]
secret_key: array[32, uint8] message: ptr uint8
message_size: csize)
to actually use it i had to change it like this:
proc crypto_ed25519_sign*(signature: array[64, uint8];
secret_key: array[32, uint8]; message: ptr openarray[uint8];
message_size: csize) {.cdecl, importc: "crypto_ed25519_sign".}
the questions are:
and give the actual msg size in message_size.
It seems system.nim declares a dummy 100_000/(big enough) sized array to avoid bound checks so i guess this is a somewhat convenient way of doing it?
greetings
Does it helps?
proc crypto_ed25519_sign(signature: array[64, uint8];
secret_key: array[32, uint8];
message: ptr uint8;
message_size: csize) {.cdecl, importc: "crypto_ed25519_sign".}
var message = newSeq[uint8]()
crypto_ed25519_sign(signature, key, cast[ptr uint8](addr message[0]), len(message))
both work in your favor and this simpler form also works (basically save some typing and let the C compiler do the pointer casting):
proc crypto_ed25519_sign(signature: array[64, uint8];
secret_key: array[32, uint8];
message: ptr;
message_size: csize) {.cdecl, importc: "crypto_ed25519_sign".}
var msg = @[0xFE.uint8, 0x32, 0xd5, 0x5C, 0x77, 0x2A, 0x49, 0x11]
crypto_ed25519_sign(sig, key, addr msg[0], len(msg))
post edit: assumption 2. not true :-), var msg = @[0xFE.uint16,...