UI_NEW(3ossl)
π
UI_NEW(3ossl) β user interface π
OpenSSL manual page, section 3ossl, all about the UI family, bestie. This is the vibe: text-based prompting, but make it customizable. β¨
β¨ NAME β¨
UI,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_dup_user_data,UI_get0_user_data,UI_get0_result,UI_get_result_length,UI_process,UI_ctrl,UI_set_default_method,UI_get_default_method,UI_get_method,UI_set_method,UI_OpenSSL,UI_nullβ user interface
πΈ SYNOPSIS πΈ
#include <openssl/ui.h>
typedef struct ui_st UI;
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);
char *UI_construct_prompt(UI *ui_method,
const char *phrase_desc, const char *object_name);
void *UI_add_user_data(UI *ui, void *user_data);
int UI_dup_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_get_result_length(UI *ui, int i);
int UI_process(UI *ui);
int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
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);
UI_METHOD *UI_OpenSSL(void);
const UI_METHOD *UI_null(void);
π DESCRIPTION π
Okay so UI stands for User Interface, and this is a general purpose set of routines for prompting the user for text-based information. Through user-written methods β see UI_create_method(3) β prompting can be done in literally any way imaginable: plain text prompting, dialog boxes, or even from a cell phone. Iconic flexibility, no cap. π
All the functions work through a context of the type UI. This context contains all the information needed to prompt correctly, plus a reference to a UI_METHOD, which is an ordered vector of functions that carry out the actual prompting.
The first thing to 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() or UI_dup_user_data(). The default UI method doesn't care about these data, but other methods might. Finally, use UI_process() to actually perform the prompting, and UI_get0_result() and UI_get_result_length() to find the result to the prompt and its length.
A UI can contain more than one prompt, which are performed in the given sequence. Each prompt gets an index number which is returned by the UI_add and UI_dup functions, and has to be used to get the corresponding result with UI_get0_result() and UI_get_result_length().
UI_process() can be called more than once on the same UI, thereby allowing a UI to have a long lifetime, but can just as well have a short lifetime. Main character energy: flexible lifespan. π
The functions are as follows:
UI_new()β creates a newUIusing the defaultUImethod. When done with thisUI, it should be freed usingUI_free().UI_new_method()β creates a newUIusing the givenUImethod. When done with thisUI, it should be freed usingUI_free().UI_OpenSSL()β returns the built-inUImethod. Note: not necessarily the default one, since the default can be changed β see further on. This method is the most machine/OS dependent part of OpenSSL and normally generates the most problems when porting. πUI_null()β returns aUImethod that does nothing. Its use is to avoid getting internal defaults for passedUI_METHODpointers.UI_free()β removes aUIfrom memory, along with all other pieces of memory that's connected to it, like duplicated input strings, results and others. IfuiisNULLnothing is done. Cleanup slay.UI_add_input_string()andUI_add_verify_string()β add a prompt to theUI, 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. No pressure, but verification failing is a whole thing. πUI_add_input_boolean()β adds a prompt to theUIthat'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 divided in two: one part being the descriptive text, given through thepromptargument, and one describing the possible answers, given through theaction_descargument. Two-part prompt, very demure. π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 built-in method, there's no technical difference between them. Other methods may make a difference between them, however.- The flags currently supported β
UI_INPUT_FLAG_ECHO, which is relevant forUI_add_input_string()and will have the users response be echoed; when prompting for a password, this flag should obviously not be used. AndUI_INPUT_FLAG_DEFAULT_PWD, which means that a default password of some sort will be used β completely depending on the application and theUImethod. Password echo? Bestie, no. π 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_addcounterparts, except that they make their own copies of all strings. Copy that, literally.UI_construct_prompt()β a helper function that can be used to create a prompt from two pieces of information: a phrase descriptionphrase_descand an object nameobject_name, where the latter may beNULL. The default constructor β if there is none provided by the method used β creates a string"Enter phrase_desc for object_name:"where the" for object_name"part is left out ifobject_nameisNULL. With the description"pass phrase"and the filename"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. Prompt glow-up achieved. β¨UI_add_user_data()β sets the user data pointer for the method to use at any time. The built-inUImethod doesn't care about this info. Note that several calls to this function doesn't add data; it replaces the previous pointer with the one given as argument. The return value is the previously set user data pointer if it was set usingUI_add_user_data()and thus the caller owns it, otherwiseNULL. Ownership tea. π«ΆUI_dup_user_data()β duplicates the user data and works as an alternative toUI_add_user_data()when the user data needs to be preserved for a longer duration, perhaps even the lifetime of the application. TheUIobject takes ownership of this duplicate and will free it whenever it gets replaced or theUIis destroyed.UI_dup_user_data()returns0on success, or-1on memory allocation failure or if the method doesn't have a duplicator and a destructor function. Memory allocation failure? Not cute. πUI_get0_user_data()β retrieves the data that has last been given to theUIwithUI_add_user_data()orUI_dup_user_data().UI_get0_result()β returns a pointer to the result buffer associated with the information indexed byi.UI_get_result_length()β returns the length of the result buffer associated with the information indexed byi.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 and0on success. Status report, bestie. π₯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 theUI, andUI_CTRL_IS_REDOABLE, which returns a flag saying if the usedUIcan be used again or not.UI_set_default_method()β changes the defaultUImethod 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 run this concurrently, fr fr. π¨UI_get_default_method()β returns a pointer to the current defaultUImethod.UI_get_method()β returns theUImethod associated with a givenUI.UI_set_method()β changes theUImethod associated with a givenUI.
π§ NOTES π§
The resulting strings that the built in method UI_OpenSSL() generate are assumed to be encoded according to the current locale or β for Windows β code page. For applications having different demands, these strings need to be converted appropriately by the caller. For Windows, if the OPENSSL_WIN32_UTF8 environment variable is set, the built-in method UI_OpenSSL() will produce UTF-8 encoded strings instead. Locale lore, Windows edition. π
π RETURN VALUES π
okay bestie, this is the part where we find out what you actually get back β because every single one of these functions has opinions about what it hands you, and you need to know the vibe check results before you start trusting return values blindly π«Ά
UI_new()andUI_new_method()β they give you a whole validUIstructure (iconic) β¨ orNULLif something went wrong.NULL= error occurred, no cap.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()β the whole girl gang π they all return a positive number on success, or a value that is less than or equal to0otherwise. so like,0is not a win here, bestie, don't get it twisted πUI_construct_prompt()β returns a string πΈ orNULLif an error occurred.UI_add_user_data()β returns the user data pointer you previously set using this same function, otherwiseNULL. it's giving "look what you left here" energy πUI_dup_user_data()β returns0on success or-1on error. simple as that, periodt.UI_get0_result()β returns a string orNULLon error πUI_get_result_length()β returns a positive integer or0on success; otherwise it returns-1on error. yes,0counts as success here, she's just built different.UI_process()β returns0on success or a negative value on error. zero is the slay outcome, iykyk π₯UI_ctrl()β returns a mask on success or-1on error. mask = you ate,-1= πUI_get_default_method(),UI_get_method(), **UI_OpenSSL()**, **UI_null()** and **UI_set_method()** β these all return either a validUI_METHODstructure orNULL`, respectively π
π¦ HISTORY π¦
so the lore: the UI_dup_user_data() function was added in OpenSSL 1.1.1. that's it, that's the whole glow-up timeline β
π COPYRIGHT π
Copyright 2001-2026 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy of the License in the file LICENSE in the source distribution, or at <https://www.openssl.org/source/license.html> π
fr fr bestie, read the license β it's the whole "you may not use this file except in compliance" thing, and we are not about to get in trouble over a missing license read π
and that's a wrap on the page, bestie π«Ά this lil beauty is from OpenSSL 3.5.6, dated 2026-04-07, and it lives at UI_NEW(3ossl) β go be iconic with your UIs now π
β¨π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms