Cedarling C API
Loading...
Searching...
No Matches
Cedarling C API

Cedarling is a local authorization engine built on the Rust Cedar Engine. The C bindings expose it as a native library: create an instance from a JSON bootstrap configuration, send authorization requests as JSON, and read results and logs back as JSON strings.

Every function is declared in cedarling_c.h. Complete, compilable programs are listed on the Examples page.

Minimal example

#include <stdio.h>
#include "cedarling_c.h"
int main(void) {
if (cedarling_init() != 0) {
return 1;
}
if (cedarling_new(bootstrap_config_json, &instance) != 0) {
fprintf(stderr, "init failed: %s\n", instance.error_message);
return 1;
}
uint64_t id = instance.instance_id;
if (cedarling_authorize_unsigned(id, request_json, &result) == 0) {
printf("%s\n", (char *)result.data);
}
return 0;
}
void cedarling_free_result(struct CedarlingResult *result)
void cedarling_cleanup(void)
void cedarling_free_instance_result(struct CedarlingInstanceResult *result)
int cedarling_new(const char *config_json, struct CedarlingInstanceResult *result)
int cedarling_authorize_unsigned(uint64_t instance_id, const char *request_json, struct CedarlingResult *result)
int cedarling_init(void)
int cedarling_shutdown(uint64_t instance_id)
Definition cedarling_c.h:58
uint64_t instance_id
Definition cedarling_c.h:66
char * error_message
Definition cedarling_c.h:70
Definition cedarling_c.h:76
char * data
Definition cedarling_c.h:84

bootstrap_config_json and request_json are JSON strings; see basic_example.c for complete values.

Memory ownership

Strings and results allocated by the library belong to the caller and must be released with the matching function: cedarling_free_string, cedarling_free_result, cedarling_free_instance_result or cedarling_free_string_array. The exception is cedarling_version(), which returns a static string that must not be freed.

Errors

Functions return 0 on success. Result structs carry an error_code (SUCCESS is 0) and an error_message; branch on error_code. For failures not described by a result struct, cedarling_get_last_error() returns a thread-local message, which must be freed with cedarling_free_string.