Artifact ffd80a403e1834cbd763a43b8416e5c49da14d30d1dbe7a1ad3b18fdb287ecbd:
- File
src/cred.c
— part of check-in
[38a6005d71]
at
2026-11-18 17:44:16
on branch stage-2
— Plan the credential project and add the credential seam
The credential project holds only sanctioned credentials, runs one authority reached over SSH, and starts after stage 2. pic gets a single function that reads the key from the environment and a wipe helper, so the helper-command source can replace it later without touching callers. (user: dmestas, size: 1136) [annotate] [blame] [check-ins using] [more...]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "cred.h" void pic_cred_wipe(void *p, size_t n) { volatile unsigned char *v = p; while (n--) { *v++ = 0; } } int pic_cred_get(const char *name, char *buf, size_t cap, char *err, size_t errcap) { const char *var, *value; size_t n; if (strcmp(name, "anthropic") == 0) { var = "ANTHROPIC_API_KEY"; } else { (void)snprintf(err, errcap, "no credential source for %s", name); return -1; } value = getenv(var); if (!value || !*value) { (void)snprintf(err, errcap, "%s is not set (run pic under `doppler run --`)", var); return -1; } n = strlen(value); if (n >= cap) { (void)snprintf(err, errcap, "%s is longer than %zu bytes", var, cap - 1); return -1; } for (size_t i = 0; i < n; i++) { if ((unsigned char)value[i] < 0x21 || (unsigned char)value[i] > 0x7e) { (void)snprintf(err, errcap, "%s has a character that cannot go in a header", var); return -1; } } memcpy(buf, value, n + 1); return 0; }