| 48 | } |
| 49 | |
| 50 | static void userconfig_source_digest(const char *state, const void *bytes, size_t len, |
| 51 | char out[CBM_SHA256_HEX_LEN + 1]) { |
| 52 | static const char domain[] = "cbm-userconfig-source-v1"; |
| 53 | cbm_sha256_ctx sha; |
| 54 | cbm_sha256_init(&sha); |
| 55 | cbm_sha256_update(&sha, domain, sizeof(domain)); |
| 56 | cbm_sha256_update(&sha, state, strlen(state) + 1); |
| 57 | if (bytes && len > 0) { |
| 58 | cbm_sha256_update(&sha, bytes, len); |
| 59 | } |
| 60 | uint8_t digest[CBM_SHA256_DIGEST_LEN]; |
| 61 | cbm_sha256_final(&sha, digest); |
| 62 | static const char hex[] = "0123456789abcdef"; |
| 63 | for (int i = 0; i < CBM_SHA256_DIGEST_LEN; i++) { |
| 64 | out[i * 2] = hex[digest[i] >> 4]; |
| 65 | out[i * 2 + 1] = hex[digest[i] & 0x0f]; |
| 66 | } |
| 67 | out[CBM_SHA256_HEX_LEN] = '\0'; |
| 68 | } |
| 69 | |
| 70 | void cbm_set_user_lang_config(const cbm_userconfig_t *cfg) { |
| 71 | g_userconfig = cfg; |
no test coverage detected