-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow integers to be used in ident concatenations
- Loading branch information
Showing
3 changed files
with
39 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
type | ||
Hash*[bits: static[int]] = object | ||
data*: array[bits div 8, uint8] | ||
|
||
{.emit: """ | ||
void sha_256(void* input, int input_len, void* output, int output_len) {} | ||
void sha_512(void* input, int input_len, void* output, int output_len) {} | ||
void keccak_256(void* input, int input_len, void* output, int output_len) {} | ||
void keccak_512(void* input, int input_len, void* output, int output_len) {} | ||
""".} | ||
|
||
template defineKeccak(bits: untyped) = | ||
proc `extKeccak bits`(output: pointer, outSize: csize, input: pointer, inputSize: csize) {.nodecl, importc: "keccak_" & astToStr(bits).} | ||
|
||
template defineSha(bits: static[int]) = | ||
proc `extSha bits`(output: pointer, outSize: csize, input: pointer, inputSize: csize) {.nodecl, importc: "sha_" & astToStr(bits).} | ||
|
||
template defineHashProcs(bits) = | ||
defineSha(bits) | ||
defineKeccak(bits) | ||
|
||
defineHashProcs(256) | ||
defineHashProcs(512) | ||
|
||
extSha256(nil, 0, nil, 0) | ||
extSha512(nil, 0, nil, 0) | ||
extKeccak256(nil, 0, nil, 0) | ||
extKeccak512(nil, 0, nil, 0) | ||
|