static void test_enum_lset(const char *name, const enum_names *en, lset_t val) { printf(" %s "PRI_LSET":\n", name, val); LSWLOG_FILE(stdout, buf) { lswlogs(buf, "\t<<"); lswlog_enum_lset_short(buf, en, "+", val); lswlogs(buf, ">>"); }
size_t lswlog_sanitized(struct lswlog *buf, const char *raw) { if (raw == NULL) { return lswlogs(buf, raw); /* appends error */ } size_t size = 0; for (const char *p = raw; *p; p++) { /* space for at least '\000' and then some */ char tmp[sizeof("\\000") + 1] = { *p, }; sanitize_string(tmp, sizeof(tmp)); size += lswlogs(buf, tmp); } return size; }
void libreswan_log_errno(int e, const char *prefix, const char *message, ...) { if (log_to_stderr) { LSWLOG_FILE(stderr, buf) { /* <prefix><PROGNAME>: <message>. Errno N: <errmess> */ lswlogs(buf, prefix); lswlogs(buf, progname); lswlogs(buf, prog_suffix); va_list args; va_start(args, message); lswlogvf(buf, message, args); va_end(args); lswlogs(buf, "."); lswlog_errno(buf, e); lswlogs(buf, "\n"); } }
size_t lswlog_enum_lset_short(struct lswlog *buf, enum_names *en, const char *separator, lset_t val) { unsigned int e; /* if nothing gets filled in, default to "none" rather than "" */ if (val == LEMPTY) { return lswlogs(buf, "none"); } size_t size = 0; const char *sep = ""; for (e = 0; val != 0; e++) { lset_t bit = LELEM(e); if (val & bit) { size += lswlogs(buf, sep); sep = separator; size += lswlog_enum_short(buf, en, e); val -= bit; } } return size; }
static void nss_ecp_calc_secret(const struct dh_desc *group, SECKEYPrivateKey **privk, SECKEYPublicKey **pubk, uint8_t *ke, size_t sizeof_ke) { passert(sizeof_ke == group->bytes); /* * Get the PK11 formatted EC parameters (stored in static * data) from NSS. */ DBG(DBG_CRYPT, DBG_log("oid %d %x", group->nss_oid, group->nss_oid)); SECOidData *pk11_data = SECOID_FindOIDByTag(group->nss_oid); if (pk11_data == NULL) { PASSERT_FAIL("Lookup of OID %d for EC group %s parameters failed", group->nss_oid, group->common.name); } LSWDBGP(DBG_CRYPT, buf) { lswlogs(buf, "pk11_data->oid: "); lswlog_nss_secitem(buf, &pk11_data->oid); }
size_t lswlog_bytes(struct lswlog *buf, const uint8_t *bytes, size_t sizeof_bytes) { if (bytes == NULL) { return lswlogs(buf, NULL); /* appends error */ } size_t size = 0; const char *sep = ""; for (size_t byte = 0; byte < sizeof_bytes; byte++) { size += lswlogf(buf, "%s%02x", sep, bytes[byte]); /* * Roughly mimic DBG_dump(): use a space separator; * and after the 4th byte, a double space separator. * * This is so that values dumped by DBG_dump() and * lswlog_bytes() have the same 'look' - make * searching and grepping easier. */ sep = (byte % 4 == 3) ? " " : " "; } return size; }
LSWDBGP(DBG_CRYPT, buf) { lswlogs(buf, "pk11_param"); lswlog_nss_secitem(buf, pk11_param); }
size_t lswlog_to_file_stream(struct lswlog *buf, FILE *file) { lswlogs(buf, "\n"); return fwrite(buf->array, buf->len, 1, file); }
void lswlog_pexpect_prefix(struct lswlog *buf) { lswlog_log_prefix(buf); lswlogs(buf, "EXPECTATION FAILED: "); }