create_new_keys(const char* jwkdir)
{
    const char* alg[] = {"ES512", "ECMR", NULL};
    char path[PATH_MAX];
    for (int i = 0; alg[i] != NULL; i++) {
        json_auto_t* jwk = jwk_generate(alg[i]);
        if (!jwk) {
            return 0;
        }
        __attribute__ ((__cleanup__(cleanup_str))) char* thp = jwk_thumbprint(jwk, DEFAULT_THP_HASH);
        if (!thp) {
            return 0;
        }
        if (snprintf(path, PATH_MAX, "%s/%s.jwk", jwkdir, thp) < 0) {
            fprintf(stderr, "Unable to prepare variable with file full path (%s)\n", thp);
            return 0;
        }
        path[sizeof(path) - 1] = '\0';
        if (json_dump_file(jwk, path, 0) == -1) {
            fprintf(stderr, "Error saving JWK to file (%s)\n", path);
            return 0;
        }

        /* Set 0440 permission for the new key. */
        if (chmod(path, S_IRUSR | S_IRGRP) == -1) {
            fprintf(stderr, "Unable to set permissions for JWK file (%s)\n", path);
            return 0;
        }
    }
    return 1;
}
create_new_keys(const char* jwkdir)
{
    const char* alg[] = {"ES512", "ECMR", NULL};
    char path[PATH_MAX];
    for (int i = 0; alg[i] != NULL; i++) {
        json_auto_t* jwk = jwk_generate(alg[i]);
        if (!jwk) {
            return 0;
        }
        __attribute__ ((__cleanup__(cleanup_str))) char* thp = jwk_thumbprint(jwk, DEFAULT_THP_HASH);
        if (!thp) {
            return 0;
        }
        if (snprintf(path, PATH_MAX, "%s/%s.jwk", jwkdir, thp) < 0) {
            fprintf(stderr, "Unable to prepare variable with file full path (%s)\n", thp);
            return 0;
        }
        path[sizeof(path) - 1] = '\0';
        if (json_dump_file(jwk, path, 0) == -1) {
            fprintf(stderr, "Error saving JWK to file (%s)\n", path);
            return 0;
        }

         
        if (chmod(path, S_IRUSR | S_IRGRP) == -1) {
            fprintf(stderr, "Unable to set permissions for JWK file (%s)\n", path);
            return 0;
        }
    }
    return 1;
}