You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rngxx/src/capi-bridge.cpp

62 lines
1.5 KiB

// Contains the work-doing code for the C API interface, which should be exported to the C API shim in the header "capi-bridge.h"
#include <rngxx.hpp>
#include <rngxx/crand.h>
#include "capi-bridge.h"
namespace bridge _export(internal)
{
void nblob(Random& restrict engine, unsigned char* restrict output, size_t es, size_t l)
{
size_t len = es * l; // full length (bytes)
}
inline void nblob(Random& restrict engine, unsigned char* restrict output, size_t len) { nblob(engine, output, 1, len); }
constexpr inline size_t ty_sizeof(rng_next_type ty)
{
//TODO:
}
constexpr inline bool ty_signed(rng_next_flag f) { return ! (f & RNG_TYQ_UNSIGNED); }
constexpr inline bool ty_signed(const rng_next_tyq& qt) { return ty_signed(qt.mod); }
}
extern "C" {
// Internal bridge members
_export(internal)
rng_t* RNG_IMPL(mkdriver)(rng_kind kind, u64* restrict seed)
{
switch(kind)
{
case RNG_KIND_CRAND:
return new rng::crand(seed[0]);
default: return NULL;
}
}
_export(internal)
int RNG_IMPL(mnext)(rng_t* restrict engine, void* restrict output, const rng_next_opt* restrict opt)
{
if(opt->ty.mod & RNG_TYQ_CHAOS) {
bridge::nblob(*engine, reinterpret_cast<unsigned char*>(output), bridge::ty_sizeof(opt->ty.type), opt->bound.len);
return 1;
}
switch(opt->ty.type)
{
case RNG_TY_BLOB: bridge::nblob(*engine, reinterpret_cast<unsigned char*>(output), opt->bound.len); break;
//TODO: Rest of types
default: return 0;
}
return 1;
}
// Direct C interface members
void rng_free(rng_t* rng)
{
delete rng;
}
}