93 lines
2.8 KiB
C
93 lines
2.8 KiB
C
#include "../src/enforcement.h"
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
static int g_passes = 0;
|
|
static int g_total = 0;
|
|
|
|
static void check_condition(const char *name, int condition) {
|
|
g_total++;
|
|
if (condition) {
|
|
printf("PASS: %s\n", name);
|
|
g_passes++;
|
|
} else {
|
|
printf("FAIL: %s\n", name);
|
|
}
|
|
}
|
|
|
|
static role_entry_t make_role(const char *purpose, const char *curve) {
|
|
role_entry_t role;
|
|
|
|
memset(&role, 0, sizeof(role));
|
|
strncpy(role.name, "test_role", sizeof(role.name) - 1);
|
|
strncpy(role.purpose_str, purpose, sizeof(role.purpose_str) - 1);
|
|
strncpy(role.curve_str, curve, sizeof(role.curve_str) - 1);
|
|
role.purpose = role_purpose_from_str(role.purpose_str);
|
|
role.curve = role_curve_from_str(role.curve_str);
|
|
|
|
return role;
|
|
}
|
|
|
|
int main(void) {
|
|
role_entry_t nostr_secp = make_role("nostr", "secp256k1");
|
|
role_entry_t bitcoin_secp = make_role("bitcoin", "secp256k1");
|
|
role_entry_t nostr_ed = make_role("nostr", "ed25519");
|
|
role_entry_t ssh_ed = make_role("ssh", "ed25519");
|
|
role_entry_t age_x = make_role("age", "x25519");
|
|
|
|
check_condition(
|
|
"sign_event + nostr/secp256k1 -> ENFORCE_OK",
|
|
enforce_verb_role(VERB_SIGN_EVENT, &nostr_secp) == ENFORCE_OK
|
|
);
|
|
|
|
check_condition(
|
|
"get_public_key + nostr/secp256k1 -> ENFORCE_OK",
|
|
enforce_verb_role(VERB_GET_PUBLIC_KEY, &nostr_secp) == ENFORCE_OK
|
|
);
|
|
|
|
check_condition(
|
|
"nip44_encrypt + nostr/secp256k1 -> ENFORCE_OK",
|
|
enforce_verb_role(VERB_NIP44_ENCRYPT, &nostr_secp) == ENFORCE_OK
|
|
);
|
|
|
|
check_condition(
|
|
"nip44_decrypt + nostr/secp256k1 -> ENFORCE_OK",
|
|
enforce_verb_role(VERB_NIP44_DECRYPT, &nostr_secp) == ENFORCE_OK
|
|
);
|
|
|
|
check_condition(
|
|
"nip04_encrypt + nostr/secp256k1 -> ENFORCE_OK",
|
|
enforce_verb_role(VERB_NIP04_ENCRYPT, &nostr_secp) == ENFORCE_OK
|
|
);
|
|
|
|
check_condition(
|
|
"sign_event + bitcoin/secp256k1 -> ENFORCE_ERR_PURPOSE",
|
|
enforce_verb_role(VERB_SIGN_EVENT, &bitcoin_secp) == ENFORCE_ERR_PURPOSE
|
|
);
|
|
|
|
check_condition(
|
|
"sign_event + nostr/ed25519 -> ENFORCE_ERR_CURVE",
|
|
enforce_verb_role(VERB_SIGN_EVENT, &nostr_ed) == ENFORCE_ERR_CURVE
|
|
);
|
|
|
|
check_condition(
|
|
"sign_event + ssh/ed25519 -> ENFORCE_ERR_PURPOSE",
|
|
enforce_verb_role(VERB_SIGN_EVENT, &ssh_ed) == ENFORCE_ERR_PURPOSE
|
|
);
|
|
|
|
check_condition(
|
|
"unknown_verb + nostr/secp256k1 -> ENFORCE_ERR_UNKNOWN_VERB",
|
|
enforce_verb_role("unknown_verb", &nostr_secp) == ENFORCE_ERR_UNKNOWN_VERB
|
|
);
|
|
|
|
check_condition(
|
|
"nip44_encrypt + age/x25519 -> ENFORCE_ERR_PURPOSE",
|
|
enforce_verb_role(VERB_NIP44_ENCRYPT, &age_x) == ENFORCE_ERR_PURPOSE
|
|
);
|
|
|
|
printf("%d/10 tests passed\n", g_passes);
|
|
|
|
return (g_passes == 10 && g_total == 10) ? 0 : 1;
|
|
}
|