]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/ui/ui_util.c
Copyright consolidation 05/10
[thirdparty/openssl.git] / crypto / ui / ui_util.c
CommitLineData
aa6bb135
RS
1/*
2 * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
44bdb056 3 *
aa6bb135
RS
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
44bdb056
RL
8 */
9
10#include <string.h>
678c1e02 11#include "ui_locl.h"
44bdb056 12
984d6c60
DW
13#ifndef BUFSIZ
14#define BUFSIZ 256
15#endif
16
0f113f3e
MC
17int UI_UTIL_read_pw_string(char *buf, int length, const char *prompt,
18 int verify)
19{
20 char buff[BUFSIZ];
21 int ret;
44bdb056 22
0f113f3e
MC
23 ret =
24 UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length,
25 prompt, verify);
26 OPENSSL_cleanse(buff, BUFSIZ);
27 return (ret);
28}
44bdb056 29
0f113f3e
MC
30int UI_UTIL_read_pw(char *buf, char *buff, int size, const char *prompt,
31 int verify)
32{
33 int ok = 0;
34 UI *ui;
44bdb056 35
0f113f3e
MC
36 if (size < 1)
37 return -1;
b57c98df 38
0f113f3e 39 ui = UI_new();
90945fa3 40 if (ui != NULL) {
0f113f3e
MC
41 ok = UI_add_input_string(ui, prompt, 0, buf, 0, size - 1);
42 if (ok >= 0 && verify)
43 ok = UI_add_verify_string(ui, prompt, 0, buff, 0, size - 1, buf);
44 if (ok >= 0)
45 ok = UI_process(ui);
46 UI_free(ui);
47 }
48 if (ok > 0)
49 ok = 0;
50 return (ok);
51}