This file contains hidden or 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
ffi = require "ffi" | |
base64 = require "base64" | |
nacl = ffi.load "sodium" | |
-- Stuff needed for random bytes | |
ffi.cdef [[ | |
void randombytes(unsigned char * const buf, const unsigned long long buf_len); | |
]] |
This file contains hidden or 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
package nacl | |
// Using libsodium for ease of building, but only relying on the original | |
// libnacl functions. | |
// #cgo LDFLAGS: -lsodium | |
// #include <sodium.h> | |
import "C" | |
import ( | |
"encoding/hex" |
This file contains hidden or 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
(require ffi/unsafe | |
ffi/unsafe/alloc | |
ffi/unsafe/define | |
test-engine/racket-tests) | |
(define (bytes->hex-string bstr) | |
(let* ([len (bytes-length bstr)] | |
[bstr2 (make-bytes (* len 2))] | |
[digit | |
(lambda (v) |
This file contains hidden or 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
;; A simple racket example that shows how to use FFI to bind to libhoedown | |
;; The end goal is to be able to make a simple function call: | |
;; | |
;; (markdown "Hello, world") ---> "<p>Hello, world</p>\n" | |
(require ffi/unsafe | |
ffi/unsafe/define | |
ffi/unsafe/alloc | |
test-engine/racket-tests) |