Debian Codegraph @

lib/util-make-failure-token.c

raw
1 /* Copyright (C) 2018-2019 Björn Esser <[email protected]>
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted.
5 *
6 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
7 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
9 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
10 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
11 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
12 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
14 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
15 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
16 * SUCH DAMAGE.
17 */
18
19 #include "crypt-port.h"
20
21 /* Fill the output buffer with a failure token. */
22 void
23 make_failure_token (const char *setting, char *output, int size)
24 {
25 if (size >= 3)
26 {
27 char token[3] = "*0";
28
29 if (setting && setting[0] == '*' && setting[1] == '0')
30 token[1] = '1';
31
32 output[0] = token[0];
33 output[1] = token[1];
34 output[2] = '\0';
35 }
36
37 /* If there's not enough space for the full failure token, do the
38 best we can. */
39 else if (size == 2)
40 {
41 output[0] = '*';
42 output[1] = '\0';
43 }
44 else if (size == 1)
45 {
46 output[0] = '\0';
47 }
48 }