Blame doc/man3/UI_new.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
UI,
Packit c4476c
UI_new, UI_new_method, UI_free, UI_add_input_string, UI_dup_input_string,
Packit c4476c
UI_add_verify_string, UI_dup_verify_string, UI_add_input_boolean,
Packit c4476c
UI_dup_input_boolean, UI_add_info_string, UI_dup_info_string,
Packit c4476c
UI_add_error_string, UI_dup_error_string, UI_construct_prompt,
Packit c4476c
UI_add_user_data, UI_dup_user_data, UI_get0_user_data, UI_get0_result,
Packit c4476c
UI_get_result_length,
Packit c4476c
UI_process, UI_ctrl, UI_set_default_method, UI_get_default_method,
Packit c4476c
UI_get_method, UI_set_method, UI_OpenSSL, UI_null - user interface
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/ui.h>
Packit c4476c
Packit c4476c
 typedef struct ui_st UI;
Packit c4476c
Packit c4476c
 UI *UI_new(void);
Packit c4476c
 UI *UI_new_method(const UI_METHOD *method);
Packit c4476c
 void UI_free(UI *ui);
Packit c4476c
Packit c4476c
 int UI_add_input_string(UI *ui, const char *prompt, int flags,
Packit c4476c
                         char *result_buf, int minsize, int maxsize);
Packit c4476c
 int UI_dup_input_string(UI *ui, const char *prompt, int flags,
Packit c4476c
                         char *result_buf, int minsize, int maxsize);
Packit c4476c
 int UI_add_verify_string(UI *ui, const char *prompt, int flags,
Packit c4476c
                          char *result_buf, int minsize, int maxsize,
Packit c4476c
                          const char *test_buf);
Packit c4476c
 int UI_dup_verify_string(UI *ui, const char *prompt, int flags,
Packit c4476c
                          char *result_buf, int minsize, int maxsize,
Packit c4476c
                          const char *test_buf);
Packit c4476c
 int UI_add_input_boolean(UI *ui, const char *prompt, const char *action_desc,
Packit c4476c
                          const char *ok_chars, const char *cancel_chars,
Packit c4476c
                          int flags, char *result_buf);
Packit c4476c
 int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
Packit c4476c
                          const char *ok_chars, const char *cancel_chars,
Packit c4476c
                          int flags, char *result_buf);
Packit c4476c
 int UI_add_info_string(UI *ui, const char *text);
Packit c4476c
 int UI_dup_info_string(UI *ui, const char *text);
Packit c4476c
 int UI_add_error_string(UI *ui, const char *text);
Packit c4476c
 int UI_dup_error_string(UI *ui, const char *text);
Packit c4476c
Packit c4476c
 char *UI_construct_prompt(UI *ui_method,
Packit c4476c
        const char *object_desc, const char *object_name);
Packit c4476c
Packit c4476c
 void *UI_add_user_data(UI *ui, void *user_data);
Packit c4476c
 int UI_dup_user_data(UI *ui, void *user_data);
Packit c4476c
 void *UI_get0_user_data(UI *ui);
Packit c4476c
Packit c4476c
 const char *UI_get0_result(UI *ui, int i);
Packit c4476c
 int UI_get_result_length(UI *ui, int i);
Packit c4476c
Packit c4476c
 int UI_process(UI *ui);
Packit c4476c
Packit c4476c
 int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
Packit c4476c
Packit c4476c
 void UI_set_default_method(const UI_METHOD *meth);
Packit c4476c
 const UI_METHOD *UI_get_default_method(void);
Packit c4476c
 const UI_METHOD *UI_get_method(UI *ui);
Packit c4476c
 const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth);
Packit c4476c
Packit c4476c
 UI_METHOD *UI_OpenSSL(void);
Packit c4476c
 const UI_METHOD *UI_null(void);
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
UI stands for User Interface, and is general purpose set of routines to
Packit c4476c
prompt the user for text-based information.  Through user-written methods
Packit c4476c
(see L<UI_create_method(3)>), prompting can be done in any way
Packit c4476c
imaginable, be it plain text prompting, through dialog boxes or from a
Packit c4476c
cell phone.
Packit c4476c
Packit c4476c
All the functions work through a context of the type UI.  This context
Packit c4476c
contains all the information needed to prompt correctly as well as a
Packit c4476c
reference to a UI_METHOD, which is an ordered vector of functions that
Packit c4476c
carry out the actual prompting.
Packit c4476c
Packit c4476c
The first thing to do is to create a UI with UI_new() or UI_new_method(),
Packit c4476c
then add information to it with the UI_add or UI_dup functions.  Also,
Packit c4476c
user-defined random data can be passed down to the underlying method
Packit c4476c
through calls to UI_add_user_data() or UI_dup_user_data().  The default
Packit c4476c
UI method doesn't care about these data, but other methods might.  Finally,
Packit c4476c
use UI_process() to actually perform the prompting and UI_get0_result()
Packit c4476c
and UI_get_result_length() to find the result to the prompt and its length.
Packit c4476c
Packit c4476c
A UI can contain more than one prompt, which are performed in the given
Packit c4476c
sequence.  Each prompt gets an index number which is returned by the
Packit c4476c
UI_add and UI_dup functions, and has to be used to get the corresponding
Packit c4476c
result with UI_get0_result() and UI_get_result_length().
Packit c4476c
Packit c4476c
UI_process() can be called more than once on the same UI, thereby allowing
Packit c4476c
a UI to have a long lifetime, but can just as well have a short lifetime.
Packit c4476c
Packit c4476c
The functions are as follows:
Packit c4476c
Packit c4476c
UI_new() creates a new UI using the default UI method.  When done with
Packit c4476c
this UI, it should be freed using UI_free().
Packit c4476c
Packit c4476c
UI_new_method() creates a new UI using the given UI method.  When done with
Packit c4476c
this UI, it should be freed using UI_free().
Packit c4476c
Packit c4476c
UI_OpenSSL() returns the built-in UI method (note: not necessarily the
Packit c4476c
default one, since the default can be changed.  See further on).  This
Packit c4476c
method is the most machine/OS dependent part of OpenSSL and normally
Packit c4476c
generates the most problems when porting.
Packit c4476c
Packit c4476c
UI_null() returns a UI method that does nothing.  Its use is to avoid
Packit c4476c
getting internal defaults for passed UI_METHOD pointers.
Packit c4476c
Packit c4476c
UI_free() removes a UI from memory, along with all other pieces of memory
Packit c4476c
that's connected to it, like duplicated input strings, results and others.
Packit c4476c
If B<ui> is NULL nothing is done.
Packit c4476c
Packit c4476c
UI_add_input_string() and UI_add_verify_string() add a prompt to the UI,
Packit c4476c
as well as flags and a result buffer and the desired minimum and maximum
Packit c4476c
sizes of the result, not counting the final NUL character.  The given
Packit c4476c
information is used to prompt for information, for example a password,
Packit c4476c
and to verify a password (i.e. having the user enter it twice and check
Packit c4476c
that the same string was entered twice).  UI_add_verify_string() takes
Packit c4476c
and extra argument that should be a pointer to the result buffer of the
Packit c4476c
input string that it's supposed to verify, or verification will fail.
Packit c4476c
Packit c4476c
UI_add_input_boolean() adds a prompt to the UI that's supposed to be answered
Packit c4476c
in a boolean way, with a single character for yes and a different character
Packit c4476c
for no.  A set of characters that can be used to cancel the prompt is given
Packit c4476c
as well.  The prompt itself is divided in two, one part being the
Packit c4476c
descriptive text (given through the I<prompt> argument) and one describing
Packit c4476c
the possible answers (given through the I<action_desc> argument).
Packit c4476c
Packit c4476c
UI_add_info_string() and UI_add_error_string() add strings that are shown at
Packit c4476c
the same time as the prompt for extra information or to show an error string.
Packit c4476c
The difference between the two is only conceptual.  With the builtin method,
Packit c4476c
there's no technical difference between them.  Other methods may make a
Packit c4476c
difference between them, however.
Packit c4476c
Packit c4476c
The flags currently supported are B<UI_INPUT_FLAG_ECHO>, which is relevant for
Packit c4476c
UI_add_input_string() and will have the users response be echoed (when
Packit c4476c
prompting for a password, this flag should obviously not be used, and
Packit c4476c
B<UI_INPUT_FLAG_DEFAULT_PWD>, which means that a default password of some
Packit c4476c
sort will be used (completely depending on the application and the UI
Packit c4476c
method).
Packit c4476c
Packit c4476c
UI_dup_input_string(), UI_dup_verify_string(), UI_dup_input_boolean(),
Packit c4476c
UI_dup_info_string() and UI_dup_error_string() are basically the same
Packit c4476c
as their UI_add counterparts, except that they make their own copies
Packit c4476c
of all strings.
Packit c4476c
Packit c4476c
UI_construct_prompt() is a helper function that can be used to create
Packit c4476c
a prompt from two pieces of information: an description and a name.
Packit c4476c
The default constructor (if there is none provided by the method used)
Packit c4476c
creates a string "Enter I<description> for I<name>:".  With the
Packit c4476c
description "pass phrase" and the file name "foo.key", that becomes
Packit c4476c
"Enter pass phrase for foo.key:".  Other methods may create whatever
Packit c4476c
string and may include encodings that will be processed by the other
Packit c4476c
method functions.
Packit c4476c
Packit c4476c
UI_add_user_data() adds a user data pointer for the method to use at any
Packit c4476c
time.  The builtin UI method doesn't care about this info.  Note that several
Packit c4476c
calls to this function doesn't add data, it replaces the previous blob
Packit c4476c
with the one given as argument.
Packit c4476c
Packit c4476c
UI_dup_user_data() duplicates the user data and works as an alternative
Packit c4476c
to UI_add_user_data() when the user data needs to be preserved for a longer
Packit c4476c
duration, perhaps even the lifetime of the application.  The UI object takes
Packit c4476c
ownership of this duplicate and will free it whenever it gets replaced or
Packit c4476c
the UI is destroyed.  UI_dup_user_data() returns 0 on success, or -1 on memory
Packit c4476c
allocation failure or if the method doesn't have a duplicator function.
Packit c4476c
Packit c4476c
UI_get0_user_data() retrieves the data that has last been given to the
Packit c4476c
UI with UI_add_user_data() or UI_dup_user_data.
Packit c4476c
Packit c4476c
UI_get0_result() returns a pointer to the result buffer associated with
Packit c4476c
the information indexed by I.
Packit c4476c
Packit c4476c
UI_get_result_length() returns the length of the result buffer associated with
Packit c4476c
the information indexed by I.
Packit c4476c
Packit c4476c
UI_process() goes through the information given so far, does all the printing
Packit c4476c
and prompting and returns the final status, which is -2 on out-of-band events
Packit c4476c
(Interrupt, Cancel, ...), -1 on error and 0 on success.
Packit c4476c
Packit c4476c
UI_ctrl() adds extra control for the application author.  For now, it
Packit c4476c
understands two commands: B<UI_CTRL_PRINT_ERRORS>, which makes UI_process()
Packit c4476c
print the OpenSSL error stack as part of processing the UI, and
Packit c4476c
B<UI_CTRL_IS_REDOABLE>, which returns a flag saying if the used UI can
Packit c4476c
be used again or not.
Packit c4476c
Packit c4476c
UI_set_default_method() changes the default UI method to the one given.
Packit c4476c
This function is not thread-safe and should not be called at the same time
Packit c4476c
as other OpenSSL functions.
Packit c4476c
Packit c4476c
UI_get_default_method() returns a pointer to the current default UI method.
Packit c4476c
Packit c4476c
UI_get_method() returns the UI method associated with a given UI.
Packit c4476c
Packit c4476c
UI_set_method() changes the UI method associated with a given UI.
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
The resulting strings that the built in method UI_OpenSSL() generate
Packit c4476c
are assumed to be encoded according to the current locale or (for
Packit c4476c
Windows) code page.
Packit c4476c
For applications having different demands, these strings need to be
Packit c4476c
converted appropriately by the caller.
Packit c4476c
For Windows, if the OPENSSL_WIN32_UTF8 environment variable is set,
Packit c4476c
the built-in method UI_OpenSSL() will produce UTF-8 encoded strings
Packit c4476c
instead.
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
UI_new() and UI_new_method() return a valid B<UI> structure or NULL if an error
Packit c4476c
occurred.
Packit c4476c
Packit c4476c
UI_add_input_string(), UI_dup_input_string(), UI_add_verify_string(),
Packit c4476c
UI_dup_verify_string(), UI_add_input_boolean(), UI_dup_input_boolean(),
Packit c4476c
UI_add_info_string(), UI_dup_info_string(), UI_add_error_string()
Packit c4476c
and UI_dup_error_string() return a positive number on success or a value which
Packit c4476c
is less than or equal to 0 otherwise.
Packit c4476c
Packit c4476c
UI_construct_prompt() returns a string or NULL if an error occurred.
Packit c4476c
Packit c4476c
UI_dup_user_data() returns 0 on success or -1 on error.
Packit c4476c
Packit c4476c
UI_get0_result() returns a string or NULL on error.
Packit c4476c
Packit c4476c
UI_get_result_length() returns a positive integer or 0 on success; otherwise it
Packit c4476c
returns -1 on error.
Packit c4476c
Packit c4476c
UI_process() returns 0 on success or a negative value on error.
Packit c4476c
Packit c4476c
UI_ctrl() returns a mask on success or -1 on error.
Packit c4476c
Packit c4476c
UI_get_default_method(), UI_get_method(), UI_OpenSSL(), UI_null() and
Packit c4476c
UI_set_method() return either a valid B<UI_METHOD> structure or NULL
Packit c4476c
respectively.
Packit c4476c
Packit c4476c
=head1 HISTORY
Packit c4476c
Packit c4476c
The UI_dup_user_data() function was added in OpenSSL 1.1.1.
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut