Created
November 30, 2020 23:06
-
-
Save divarvel/39737925df95ca3a7a8bd94788d793c4 to your computer and use it in GitHub Desktop.
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
{-# LANGUAGE QuasiQuotes #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
module Inline where | |
import Data.ByteString (ByteString, copy, packCStringLen) | |
import Foreign.Marshal.Alloc | |
import qualified Language.C.Inline as C | |
C.context (C.baseCtx <> C.bsCtx) | |
C.include "biscuit_auth.h" | |
main :: IO () | |
main = putStrLn "x" | |
genKp :: ByteString | |
-> IO (ByteString, ByteString) | |
genKp seed = | |
allocaBytes 32 $ \keyPairBuf -> | |
allocaBytes 32 $ \pubKeyBuf -> do | |
[C.block| | |
void { | |
KeyPair * kp = key_pair_new($bs-ptr:seed, $bs-len:seed); | |
PublicKey * pubkey = key_pair_public(kp); | |
key_pair_serialize(kp, $(char* keyPairBuf)); | |
public_key_serialize(pubkey, $(char* pubKeyBuf)); | |
//public_key_free(pubkey); | |
key_pair_free(kp); | |
return; | |
} | |
|] | |
(,) <$> packCStringLen (keyPairBuf, 32) <*> packCStringLen (pubKeyBuf, 32) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment