Coverage Report

Created: 2026-01-17 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gnupg/common/agent-opt.c
Line
Count
Source
1
/* agent-opt.c - Helper for certain agent options
2
 * Copyright (C) 2013 Free Software Foundation, Inc.
3
 *
4
 * This file is part of GnuPG.
5
 *
6
 * This file is free software; you can redistribute it and/or modify
7
 * it under the terms of either
8
 *
9
 *   - the GNU Lesser General Public License as published by the Free
10
 *     Software Foundation; either version 3 of the License, or (at
11
 *     your option) any later version.
12
 *
13
 * or
14
 *
15
 *   - the GNU General Public License as published by the Free
16
 *     Software Foundation; either version 2 of the License, or (at
17
 *     your option) any later version.
18
 *
19
 * or both in parallel, as here.
20
 *
21
 * This file is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
28
 */
29
30
#include <config.h>
31
#include <stdlib.h>
32
#include <string.h>
33
34
#include "shareddefs.h"
35
36
37
/* Parse VALUE and return an integer representing a pinentry_mode_t.
38
   (-1) is returned for an invalid VALUE.  */
39
int
40
parse_pinentry_mode (const char *value)
41
0
{
42
0
  int result;
43
44
0
  if (!strcmp (value, "ask") || !strcmp (value, "default"))
45
0
    result = PINENTRY_MODE_ASK;
46
0
  else if (!strcmp (value, "cancel"))
47
0
    result = PINENTRY_MODE_CANCEL;
48
0
  else if (!strcmp (value, "error"))
49
0
    result = PINENTRY_MODE_ERROR;
50
0
  else if (!strcmp (value, "loopback"))
51
0
    result = PINENTRY_MODE_LOOPBACK;
52
0
  else
53
0
    result = -1;
54
55
0
  return result;
56
0
}
57
58
/* Return the string representation for the pinentry MODE.  Returns
59
   "?" for an invalid mode.  */
60
const char *
61
str_pinentry_mode (pinentry_mode_t mode)
62
0
{
63
0
  switch (mode)
64
0
    {
65
0
    case PINENTRY_MODE_ASK:      return "ask";
66
0
    case PINENTRY_MODE_CANCEL:   return "cancel";
67
0
    case PINENTRY_MODE_ERROR:    return "error";
68
0
    case PINENTRY_MODE_LOOPBACK: return "loopback";
69
0
    }
70
0
 return "?";
71
0
}
72
73
74
/* Parse VALUE and return an integer representing a request_origin_t.
75
 * (-1) is returned for an invalid VALUE.  */
76
int
77
parse_request_origin (const char *value)
78
0
{
79
0
  int result;
80
81
0
  if (!strcmp (value, "none") || !strcmp (value, "local"))
82
0
    result = REQUEST_ORIGIN_LOCAL;
83
0
  else if (!strcmp (value, "remote"))
84
0
    result = REQUEST_ORIGIN_REMOTE;
85
0
  else if (!strcmp (value, "browser"))
86
0
    result = REQUEST_ORIGIN_BROWSER;
87
0
  else
88
0
    result = -1;
89
90
0
  return result;
91
0
}
92
93
94
/* Return the string representation for the request origin.  Returns
95
 * "?" for an invalid mode.  */
96
const char *
97
str_request_origin (request_origin_t mode)
98
0
{
99
0
  switch (mode)
100
0
    {
101
0
    case REQUEST_ORIGIN_LOCAL:   return "local";
102
0
    case REQUEST_ORIGIN_REMOTE:  return "remote";
103
0
    case REQUEST_ORIGIN_BROWSER: return "browser";
104
0
    }
105
0
 return "?";
106
0
}