UI_NEW(3)
π UI_NEW(3) β New User Interface π
okay bestie, welcome to UI_NEW(3) from the Library Functions Manual, and this one is literally the whole user-interface crew of libcrypto. like, all of them. every single one. let's go π
β¨ NAME β¨
UI_new, UI_new_method, UI_free, UI_add_input_string, UI_dup_input_string, UI_add_verify_string, UI_dup_verify_string, UI_add_input_boolean, UI_dup_input_boolean, UI_add_info_string, UI_dup_info_string, UI_add_error_string, UI_dup_error_string, UI_construct_prompt, UI_add_user_data, UI_get0_user_data, UI_get0_result, UI_process, UI_ctrl, UI_set_default_method, UI_get_default_method, UI_get_method, UI_set_method, UI_OpenSSL, UI_null β New User Interface
yes that's a lot of names, she's an icon with a big family π«Ά
πΈ SYNOPSIS πΈ
library βlibcryptoβ
#include <openssl/ui.h>
UI *
UI_new(void);
UI *
UI_new_method(const UI_METHOD *method);
void
UI_free(UI *ui);
int
UI_add_input_string(UI *ui, const char *prompt, int flags,
char *result_buf, int minsize, int maxsize);
int
UI_dup_input_string(UI *ui, const char *prompt, int flags,
char *result_buf, int minsize, int maxsize);
int
UI_add_verify_string(UI *ui, const char *prompt, int flags,
char *result_buf, int minsize, int maxsize, const char *test_buf);
int
UI_dup_verify_string(UI *ui, const char *prompt, int flags,
char *result_buf, int minsize, int maxsize, const char *test_buf);
int
UI_add_input_boolean(UI *ui, const char *prompt,
const char *action_desc, const char *ok_chars,
const char *cancel_chars, int flags, char *result_buf);
int
UI_dup_input_boolean(UI *ui, const char *prompt,
const char *action_desc, const char *ok_chars,
const char *cancel_chars, int flags, char *result_buf);
int
UI_add_info_string(UI *ui, const char *text);
int
UI_dup_info_string(UI *ui, const char *text);
int
UI_add_error_string(UI *ui, const char *text);
int
UI_dup_error_string(UI *ui, const char *text);
/* These are the possible flags. They can be OR'ed together. */
#define UI_INPUT_FLAG_ECHO 0x01
#define UI_INPUT_FLAG_DEFAULT_PWD 0x02
char *
UI_construct_prompt(UI *ui_method, const char *object_desc,
const char *object_name);
void *
UI_add_user_data(UI *ui, void *user_data);
void *
UI_get0_user_data(UI *ui);
const char *
UI_get0_result(UI *ui, int i);
int
UI_process(UI *ui);
int
UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
#define UI_CTRL_PRINT_ERRORS 1
#define UI_CTRL_IS_REDOABLE 2
void
UI_set_default_method(const UI_METHOD *meth);
const UI_METHOD *
UI_get_default_method(void);
const UI_METHOD *
UI_get_method(UI *ui);
const UI_METHOD *
UI_set_method(UI *ui, const UI_METHOD *meth);
const UI_METHOD *
UI_OpenSSL(void);
const UI_METHOD *
UI_null(void);
π DESCRIPTION π
so UI stands for User Interface (not the CSS framework, focus π), and this whole thing is a general purpose set of routines to prompt the user for text-based information. and the way it does that? through user-written methods (peep UI_create_method(3)) β so prompting can be done in literally any way imaginable. plain text prompting? slay. dialog boxes? slay. from a cell phone?? also slay, apparently π±β¨
all the functions work through a context of the type UI. this context holds everything needed to prompt correctly, plus a reference to a UI_METHOD, which is an ordered vector of functions that do the actual prompting. think of it as the group chat and the UI_METHOD is the friend who actually sends the message π«Ά
so the first thing you do is create a UI with UI_new() or UI_new_method(), then add information to it with the UI_add_*() or UI_dup_*() functions. also, user-defined random data can be passed down to the underlying method through calls to UI_add_user_data(). the default UI method literally does not care about these data, but other methods might π. finally, use UI_process() to actually perform the prompting and UI_get0_result() to find the result to the prompt. main character energy from start to finish.
a UI can contain more than one prompt, and they're performed in the given sequence. each prompt gets an index number which is returned by the UI_add_*() and UI_dup_*() functions, and you have to use that to get the corresponding result with UI_get0_result(). iykyk.
the functions are as follows:
UI_new()β creates a newUIusing the default UI method. when you're done with thisUI, it should be freed usingUI_free().UI_new_method()β creates a newUIusing the given UI method. when done, free it withUI_free(). same vibe, different method πUI_OpenSSL()β returns the built-in UI method. β οΈ note: not necessarily the default one, since the default can be changed (see further on bestie). this method is the most machine/OS dependent part of OpenSSL and normally generates the most problems when porting. it's giving "works on my machine" πUI_null()β returns a UI method that does nothing. its whole purpose is to avoid getting internal defaults for passedUI_METHODpointers.UI_free()β removes ui from memory, along with all other pieces of memory connected to it, like duplicated input strings, results and others. if ui is aNULLpointer, no action occurs. no drama, no crash πUI_add_input_string()andUI_add_verify_string()β add a prompt to ui, as well as flags and a result buffer and the desired minimum and maximum sizes of the result, not counting the finalNULcharacter. the given information is used to prompt for information (for example a password) and to verify a password β i.e. having the user enter it twice and check that the same string was entered twice.UI_add_verify_string()takes an extra argument that should be a pointer to the result buffer of the input string that it's supposed to verify, or verification will fail. so like, actually pass it πUI_add_input_boolean()β adds a prompt to ui that's supposed to be answered in a boolean way, with a single character for yes and a different character for no. a set of characters that can be used to cancel the prompt is given as well. the prompt itself is really divided in two: one part is the descriptive text (given through the prompt argument) and one describes the possible answers (given through the action_desc argument). two prompts in a trench coat π§₯UI_add_info_string()andUI_add_error_string()β add strings that are shown at the same time as the prompt, for extra information or to show an error string. the difference between the two is only conceptual. with the builtin method there's no technical difference between them at all. other methods may make a difference though, so don't @ me πUI_dup_input_string(),UI_dup_verify_string(),UI_dup_input_boolean(),UI_dup_info_string(), andUI_dup_error_string()β basically the same as theirUI_add_*()counterparts, except that they make their own copies of all strings. copy-paste but make it official π
the flags currently supported are:
UI_INPUT_FLAG_ECHOβ relevant forUI_add_input_string(), and will have the user's response be echoed. when prompting for a password, this flag should obviously not be used π¨UI_INPUT_FLAG_DEFAULT_PWDβ means that a default password of some sort will be used (completely depending on the application and the UI method).
and the rest of the crew:
UI_construct_prompt()β a helper function that can be used to create a prompt from two pieces of information: a description and a name. the default constructor (if there is none provided by the method used) creates a string"Enter description for name:". with the description"pass phrase"and the file name"foo.key", that becomes"Enter pass phrase for foo.key:". other methods may create whatever string and may include encodings that will be processed by the other method functions. customizable queen πUI_add_user_data()β adds a user data pointer for the method to use at any time. the builtin UI method doesn't care about this info. β οΈ note that several calls to this function don't add data β the previous blob is replaced with the one given as argument. not a stack, bestie, it's a swap πUI_get0_user_data()β retrieves the data that has last been given to the ui withUI_add_user_data().UI_get0_result()β returns a pointer to the result buffer associated with the information indexed by i.UI_process()β goes through the information given so far, does all the printing and prompting, and returns the final status, which is-2on out-of-band events (Interrupt, Cancel, ...),-1on error, or0on success.UI_ctrl()β adds extra control for the application author. for now it understands two commands:UI_CTRL_PRINT_ERRORS, which makesUI_process()print the OpenSSL error stack as part of processing the ui, andUI_CTRL_IS_REDOABLE, which returns a flag saying if the used ui can be used again or not. redoable is a real word now, we don't question it β¨UI_set_default_method()β changes the default UI method to the one given. π¨ this function is not thread-safe and should not be called at the same time as other OpenSSL functions. do not test her.UI_get_default_method()β returns a pointer to the current default UI method.UI_get_method()β returns the UI method associated with a given ui.UI_set_method()β changes the UI method associated with a given ui.
π¦ RETURN VALUES π¦
UI_new()andUI_new_method()return a validUIstructure orNULLif an error occurred.UI_add_input_string(),UI_dup_input_string(),UI_add_verify_string(),UI_dup_verify_string(),UI_add_input_boolean(),UI_dup_input_boolean(),UI_add_info_string(),UI_dup_info_string(),UI_add_error_string(), andUI_dup_error_string()return a positive number on success or a number less than or equal to zero otherwise.UI_construct_prompt()andUI_get0_result()return a string orNULLif an error occurred.UI_add_user_data()andUI_get0_user_data()return a pointer to the user data that was contained in ui before the call. in particular,NULLis a valid return value β don't panic, she's fine πUI_process()returns0on success or a negative value on error.UI_ctrl()returns a mask on success or-1on error.UI_get_default_method(),UI_OpenSSL()andUI_null()always return a pointer to a validUI_METHODstructure. always. no cap π―UI_get_method()andUI_set_method()return a pointer to theUI_METHODstructure that is installed in ui after the call. the OpenSSL documentation says that they can fail and returnNULL, but currently this can only happen when and afterUI_set_method()is called with an explicitNULLargument. so like, extremely specific circumstances π
π₯ SEE ALSO π₯
crypto(3), UI_create_method(3), UI_get_string_type(3)
go read those too, bestie, they're part of the lore π
π HISTORY π
these functions first appeared in OpenSSL 0.9.7 and have been available since OpenBSD 3.2. vintage icons β¨
UI_null() first appeared in OpenSSL 1.1.1 and has been available since OpenBSD 7.3. the baby of the family πΌ
π AUTHORS π
Richard Levitte <richard@levitte.org> for the OpenSSL project.
and that's the whole page, bestie π«Ά this UI_NEW(3) situation is from the Debian build of the Library Functions Manual, dated June 8, 2025 β go forth and prompt responsibly π
β¨
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2001, 2016, 2017 The OpenSSL Project. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms