Coverage Report

Created: 2026-12-01 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hpn-ssh/ossl3-provider-err.c
Line
Count
Source
1
/* CC0 license applied, see LICENCE.md */
2
3
#include <assert.h>
4
#include <stdlib.h>
5
#include "ossl3-provider-err.h"
6
7
#ifdef WITH_OPENSSL3
8
9
struct proverr_functions_st {
10
  const OSSL_CORE_HANDLE *core;
11
  OSSL_FUNC_core_new_error_fn *core_new_error;
12
  OSSL_FUNC_core_set_error_debug_fn *core_set_error_debug;
13
  OSSL_FUNC_core_vset_error_fn *core_vset_error;
14
};
15
16
struct proverr_functions_st *
17
proverr_new_handle(const OSSL_CORE_HANDLE *core, const OSSL_DISPATCH *dispatch)
18
0
{
19
  /*
20
   * libcrypto gives providers the tools to create error routines similar
21
   * to the ones defined in <openssl/err.h>
22
   */
23
0
  OSSL_FUNC_core_new_error_fn *c_new_error = NULL;
24
0
  OSSL_FUNC_core_set_error_debug_fn *c_set_error_debug = NULL;
25
0
  OSSL_FUNC_core_vset_error_fn *c_vset_error = NULL;
26
0
  struct proverr_functions_st *handle = NULL;
27
28
0
  assert(core != NULL);
29
0
  assert(dispatch != NULL);
30
31
0
#ifndef DEBUG
32
0
  if (core == NULL || dispatch == NULL)
33
0
    return NULL;
34
0
#endif
35
36
0
  for (; dispatch->function_id != 0; dispatch++)
37
0
    switch (dispatch->function_id) {
38
0
    case OSSL_FUNC_CORE_NEW_ERROR:
39
0
      c_new_error = OSSL_FUNC_core_new_error(dispatch);
40
0
      break;
41
0
    case OSSL_FUNC_CORE_SET_ERROR_DEBUG:
42
0
      c_set_error_debug = OSSL_FUNC_core_set_error_debug(dispatch);
43
0
      break;
44
0
    case OSSL_FUNC_CORE_VSET_ERROR:
45
0
      c_vset_error = OSSL_FUNC_core_vset_error(dispatch);
46
0
      break;
47
0
    }
48
49
0
  assert(c_new_error != NULL);
50
0
  assert(c_set_error_debug != NULL);
51
0
  assert(c_vset_error != NULL);
52
53
#ifdef NDEBUG
54
  if (c_new_error == NULL || c_set_error_debug == NULL || c_vset_error == NULL)
55
    return NULL;
56
#endif
57
58
0
  if ((handle = malloc(sizeof(*handle))) != NULL) {
59
0
    handle->core = core;
60
0
    handle->core_new_error = c_new_error;
61
0
    handle->core_set_error_debug = c_set_error_debug;
62
0
    handle->core_vset_error = c_vset_error;
63
0
  }
64
0
  return handle;
65
0
}
66
67
struct proverr_functions_st *
68
proverr_dup_handle(struct proverr_functions_st *src)
69
0
{
70
0
  struct proverr_functions_st *dst = NULL;
71
72
0
  if (src != NULL
73
0
      && (dst = malloc(sizeof(*dst))) != NULL) {
74
0
    dst->core = src->core;
75
0
    dst->core_new_error = src->core_new_error;
76
0
    dst->core_set_error_debug = src->core_set_error_debug;
77
0
    dst->core_vset_error = src->core_vset_error;
78
0
  }
79
0
  return dst;
80
0
}
81
82
void proverr_free_handle(struct proverr_functions_st *handle)
83
0
{
84
0
  free(handle);
85
0
}
86
87
void proverr_new_error(const struct proverr_functions_st *handle)
88
0
{
89
0
  handle->core_new_error(handle->core);
90
0
}
91
92
void proverr_set_error_debug(const struct proverr_functions_st *handle,
93
                             const char *file, int line, const char *func)
94
0
{
95
0
  handle->core_set_error_debug(handle->core, file, line, func);
96
0
}
97
98
void proverr_set_error(const struct proverr_functions_st *handle,
99
                       uint32_t reason, const char *fmt, ...)
100
0
{
101
0
  va_list ap;
102
103
0
  va_start(ap, fmt);
104
0
  handle->core_vset_error(handle->core, reason, fmt, ap);
105
  va_end(ap);
106
0
}
107
108
#endif /* WITH_OPENSSL3 */