Home /Modules/os-level-support/test_grt_claim.c

test_grt_claim.c

os-level-support/trust/test_grt_claim.c · 34 line(s) · c

#include "grt_claim.h"
#include <assert.h>
#include <string.h>

int main(void) {
    grt_claim claim;
    memset(&claim, 0, sizeof(claim));
    claim.version = 1;
    claim.kind = GRT_KIND_PROJECT_IDENTITY;
    strcpy(claim.subject_id, "project:example");
    strcpy(claim.issuer_id, "issuer:example");
    strcpy(claim.component, "os-level-support");
    strcpy(claim.platform_scope, "linux,macos,windows");
    strcpy(claim.limitations, "identity and provenance not cryptographically verified");
    strcpy(claim.policy_version, "concept-1");
    claim.issued_at = 100;
    claim.expires_at = 200;

    assert(grt_claim_validate(&claim, 150) == GRT_CLAIM_WELL_FORMED);
    assert(strcmp(grt_claim_status_name(GRT_CLAIM_WELL_FORMED), "well-formed-unverified") == 0);
    assert(grt_claim_validate(&claim, 200) == GRT_CLAIM_EXPIRED);
    claim.expires_at = 99;
    assert(grt_claim_validate(&claim, 50) == GRT_CLAIM_INVALID);
    claim.expires_at = 200;
    claim.kind = GRT_KIND_ARTIFACT_PROVENANCE;
    strcpy(claim.source_revision, "rev-1");
    strcpy(claim.artifact_digest_algorithm, "SHA-256");
    strcpy(claim.artifact_digest, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");
    assert(grt_claim_validate(&claim, 150) == GRT_CLAIM_WELL_FORMED);
    claim.artifact_digest[4] = 'z';
    assert(grt_claim_validate(&claim, 150) == GRT_CLAIM_INVALID);
    return 0;
}