xref: /openbsd-src/lib/libcrypto/man/UI_create_method.3 (revision e699d1b413e4ea12a9c093e720b1e5ff28c466f5)
1*e699d1b4Stb.\"	$OpenBSD: UI_create_method.3,v 1.6 2023/05/22 19:38:04 tb Exp $
2ec291200Sschwarze.\"	OpenSSL UI_create_method.pod 8e3d46e5 Mar 11 10:51:04 2017 +0100
3ec291200Sschwarze.\"
4ec291200Sschwarze.\" This file was written by Richard Levitte <levitte@openssl.org>.
5ec291200Sschwarze.\" Copyright (c) 2017 The OpenSSL Project.  All rights reserved.
6ec291200Sschwarze.\"
7ec291200Sschwarze.\" Redistribution and use in source and binary forms, with or without
8ec291200Sschwarze.\" modification, are permitted provided that the following conditions
9ec291200Sschwarze.\" are met:
10ec291200Sschwarze.\"
11ec291200Sschwarze.\" 1. Redistributions of source code must retain the above copyright
12ec291200Sschwarze.\"    notice, this list of conditions and the following disclaimer.
13ec291200Sschwarze.\"
14ec291200Sschwarze.\" 2. Redistributions in binary form must reproduce the above copyright
15ec291200Sschwarze.\"    notice, this list of conditions and the following disclaimer in
16ec291200Sschwarze.\"    the documentation and/or other materials provided with the
17ec291200Sschwarze.\"    distribution.
18ec291200Sschwarze.\"
19ec291200Sschwarze.\" 3. All advertising materials mentioning features or use of this
20ec291200Sschwarze.\"    software must display the following acknowledgment:
21ec291200Sschwarze.\"    "This product includes software developed by the OpenSSL Project
22ec291200Sschwarze.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23ec291200Sschwarze.\"
24ec291200Sschwarze.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25ec291200Sschwarze.\"    endorse or promote products derived from this software without
26ec291200Sschwarze.\"    prior written permission. For written permission, please contact
27ec291200Sschwarze.\"    openssl-core@openssl.org.
28ec291200Sschwarze.\"
29ec291200Sschwarze.\" 5. Products derived from this software may not be called "OpenSSL"
30ec291200Sschwarze.\"    nor may "OpenSSL" appear in their names without prior written
31ec291200Sschwarze.\"    permission of the OpenSSL Project.
32ec291200Sschwarze.\"
33ec291200Sschwarze.\" 6. Redistributions of any form whatsoever must retain the following
34ec291200Sschwarze.\"    acknowledgment:
35ec291200Sschwarze.\"    "This product includes software developed by the OpenSSL Project
36ec291200Sschwarze.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37ec291200Sschwarze.\"
38ec291200Sschwarze.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39ec291200Sschwarze.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40ec291200Sschwarze.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41ec291200Sschwarze.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
42ec291200Sschwarze.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43ec291200Sschwarze.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44ec291200Sschwarze.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45ec291200Sschwarze.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46ec291200Sschwarze.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47ec291200Sschwarze.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48ec291200Sschwarze.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49ec291200Sschwarze.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50ec291200Sschwarze.\"
51*e699d1b4Stb.Dd $Mdocdate: May 22 2023 $
52ec291200Sschwarze.Dt UI_CREATE_METHOD 3
53ec291200Sschwarze.Os
54ec291200Sschwarze.Sh NAME
55ec291200Sschwarze.Nm UI_create_method ,
56ec291200Sschwarze.Nm UI_destroy_method ,
57ec291200Sschwarze.Nm UI_method_set_opener ,
58ec291200Sschwarze.Nm UI_method_set_writer ,
59ec291200Sschwarze.Nm UI_method_set_flusher ,
60ec291200Sschwarze.Nm UI_method_set_reader ,
61ec291200Sschwarze.Nm UI_method_set_closer ,
62ec291200Sschwarze.Nm UI_method_set_prompt_constructor ,
63ec291200Sschwarze.Nm UI_method_get_opener ,
64ec291200Sschwarze.Nm UI_method_get_writer ,
65ec291200Sschwarze.Nm UI_method_get_flusher ,
66ec291200Sschwarze.Nm UI_method_get_reader ,
67ec291200Sschwarze.Nm UI_method_get_closer ,
68ec291200Sschwarze.Nm UI_method_get_prompt_constructor
69ec291200Sschwarze.Nd user interface method creation and destruction
70ec291200Sschwarze.Sh SYNOPSIS
71ec291200Sschwarze.In openssl/ui.h
72ec291200Sschwarze.Ft UI_METHOD *
73ec291200Sschwarze.Fo UI_create_method
746c201230Sschwarze.Fa "const char *name"
75ec291200Sschwarze.Fc
76ec291200Sschwarze.Ft void
77ec291200Sschwarze.Fo UI_destroy_method
78ec291200Sschwarze.Fa "UI_METHOD *ui_method"
79ec291200Sschwarze.Fc
80ec291200Sschwarze.Ft int
81ec291200Sschwarze.Fo UI_method_set_opener
82ec291200Sschwarze.Fa "UI_METHOD *method"
83ec291200Sschwarze.Fa "int (*opener)(UI *ui)"
84ec291200Sschwarze.Fc
85ec291200Sschwarze.Ft int
86ec291200Sschwarze.Fo UI_method_set_writer
87ec291200Sschwarze.Fa "UI_METHOD *method"
88ec291200Sschwarze.Fa "int (*writer)(UI *ui, UI_STRING *uis)"
89ec291200Sschwarze.Fc
90ec291200Sschwarze.Ft int
91ec291200Sschwarze.Fo UI_method_set_flusher
92ec291200Sschwarze.Fa "UI_METHOD *method"
93ec291200Sschwarze.Fa "int (*flusher)(UI *ui)"
94ec291200Sschwarze.Fc
95ec291200Sschwarze.Ft int
96ec291200Sschwarze.Fo UI_method_set_reader
97ec291200Sschwarze.Fa "UI_METHOD *method"
98ec291200Sschwarze.Fa "int (*reader)(UI *ui, UI_STRING *uis)"
99ec291200Sschwarze.Fc
100ec291200Sschwarze.Ft int
101ec291200Sschwarze.Fo UI_method_set_closer
102ec291200Sschwarze.Fa "UI_METHOD *method"
103ec291200Sschwarze.Fa "int (*closer)(UI *ui)"
104ec291200Sschwarze.Fc
105ec291200Sschwarze.Ft int
106ec291200Sschwarze.Fo UI_method_set_prompt_constructor
107ec291200Sschwarze.Fa "UI_METHOD *method"
108ec291200Sschwarze.Fa "char *(*prompt_constructor)(UI *ui, const char *object_desc,\
109ec291200Sschwarze const char *object_name)"
110ec291200Sschwarze.Fc
111ec291200Sschwarze.Ft int
112ec291200Sschwarze.Fo "(*UI_method_get_opener(const UI_METHOD *method))"
113*e699d1b4Stb.Fa "UI *"
114ec291200Sschwarze.Fc
115ec291200Sschwarze.Ft int
116ec291200Sschwarze.Fo "(*UI_method_get_writer(const UI_METHOD *method))"
117ec291200Sschwarze.Fa "UI *"
118ec291200Sschwarze.Fa "UI_STRING *"
119ec291200Sschwarze.Fc
120ec291200Sschwarze.Ft int
121ec291200Sschwarze.Fo "(*UI_method_get_flusher(const UI_METHOD *method))"
122ec291200Sschwarze.Fa "UI *"
123ec291200Sschwarze.Fc
124ec291200Sschwarze.Ft int
125ec291200Sschwarze.Fo "(*UI_method_get_reader(const UI_METHOD *method))"
126ec291200Sschwarze.Fa "UI *"
127ec291200Sschwarze.Fa "UI_STRING *"
128ec291200Sschwarze.Fc
129ec291200Sschwarze.Ft int
130ec291200Sschwarze.Fo "(*UI_method_get_closer(const UI_METHOD *method))"
131ec291200Sschwarze.Fa "UI *"
132ec291200Sschwarze.Fc
133ec291200Sschwarze.Ft char *
134ec291200Sschwarze.Fo "(*UI_method_get_prompt_constructor(UI_METHOD *method))"
135ec291200Sschwarze.Fa "UI *"
136ec291200Sschwarze.Fa "const char *"
137ec291200Sschwarze.Fa "const char *"
138ec291200Sschwarze.Fc
139ec291200Sschwarze.Sh DESCRIPTION
140ec291200SschwarzeA method contains a few functions that implement the low level of the
141ec291200SschwarzeUser Interface.
142ec291200SschwarzeThese functions are:
143ec291200Sschwarze.Bl -tag -width Ds
144ec291200Sschwarze.It an opener
145ec291200SschwarzeThis function takes a reference to a UI and starts a session, for
146ec291200Sschwarzeexample by opening a channel to a tty, or by creating a dialog box.
147ec291200Sschwarze.It a writer
148ec291200SschwarzeThis function takes a reference to a UI and a UI String, and writes the
149ec291200Sschwarzestring where appropriate, maybe to the tty, maybe added as a field label
150ec291200Sschwarzein a dialog box.
151ec291200SschwarzeNote that this gets fed all strings associated with a UI, one after the
152ec291200Sschwarzeother, so care must be taken which ones it actually uses.
153ec291200Sschwarze.It a flusher
154ec291200SschwarzeThis function takes a reference to a UI, and flushes everything that has
155ec291200Sschwarzebeen output so far.
156ec291200SschwarzeFor example, if the method builds up a dialog box, this can be used to
157ec291200Sschwarzeactually display it and accepting input ended with a pressed button.
158ec291200Sschwarze.It a reader
159ec291200SschwarzeThis function takes a reference to a UI and a UI string and reads off
160ec291200Sschwarzethe given prompt, maybe from the tty, maybe from a field in a dialog
161ec291200Sschwarzebox.
162ec291200SschwarzeNote that this gets fed all strings associated with a UI, one after the
163ec291200Sschwarzeother, so care must be taken which ones it actually uses.
164ec291200Sschwarze.It a closer
165ec291200SschwarzeThis function takes a reference to a UI, and closes the session, maybe
166ec291200Sschwarzeby closing the channel to the tty, maybe by destroying a dialog box.
167ec291200Sschwarze.El
168ec291200Sschwarze.Pp
169ec291200SschwarzeAll of these functions are expected to return 0 on error, 1 on success,
170ec291200Sschwarzeor -1 on out-off-band events, for example if some prompting has been
171ec291200Sschwarzecancelled (by pressing Ctrl-C, for example).
1728bc087ceSjmcOnly the flusher or the reader are expected to return -1.
1738bc087ceSjmcIf returned by another of the functions, it's treated as if 0 was returned.
174ec291200Sschwarze.Pp
175ec291200SschwarzeRegarding the writer and the reader, don't assume the former should only
176ec291200Sschwarzewrite and don't assume the latter should only read.
177ec291200SschwarzeThis depends on the needs of the method.
178ec291200Sschwarze.Pp
179ec291200SschwarzeFor example, a typical tty reader wouldn't write the prompts in the
180ec291200Sschwarzewrite, but would rather do so in the reader, because of the sequential
181ec291200Sschwarzenature of prompting on a tty.
182ec291200SschwarzeThis is how the
183ec291200Sschwarze.Xr UI_OpenSSL 3
184ec291200Sschwarzemethod does it.
185ec291200Sschwarze.Pp
186ec291200SschwarzeIn contrast, a method that builds up a dialog box would add all prompt
187ec291200Sschwarzetext in the writer, have all input read in the flusher and store the
188ec291200Sschwarzeresults in some temporary buffer, and finally have the reader just fetch
189ec291200Sschwarzethose results.
190ec291200Sschwarze.Pp
191ec291200SschwarzeThe central function that uses these method functions is
192ec291200Sschwarze.Xr UI_process 3 ,
193ec291200Sschwarzeand it does it in five steps:
194ec291200Sschwarze.Bl -enum
195ec291200Sschwarze.It
196ec291200SschwarzeOpen the session using the opener function if that one is defined.
197ec291200SschwarzeIf an error occurs, jump to 5.
198ec291200Sschwarze.It
199ec291200SschwarzeFor every UI String associated with the UI, call the writer function if
200ec291200Sschwarzethat one is defined.
201ec291200SschwarzeIf an error occurs, jump to 5.
202ec291200Sschwarze.It
203ec291200SschwarzeFlush everything using the flusher function if that one is defined.
204ec291200SschwarzeIf an error occurs, jump to 5.
205ec291200Sschwarze.It
206ec291200SschwarzeFor every UI String associated with the UI, call the reader function if
207ec291200Sschwarzethat one is defined.
208ec291200SschwarzeIf an error occurs, jump to 5.
209ec291200Sschwarze.It
210ec291200SschwarzeClose the session using the closer function if that one is defined.
211ec291200Sschwarze.El
212ec291200Sschwarze.Pp
213ec291200Sschwarze.Fn UI_create_method
214ec291200Sschwarzecreates a new UI method with a given
215ec291200Sschwarze.Fa name .
216ec291200Sschwarze.Pp
217ec291200Sschwarze.Fn UI_destroy_method
218ec291200Sschwarzedestroys the given
219ec291200Sschwarze.Fa ui_method .
220ec291200Sschwarze.Pp
221ec291200Sschwarze.Fn UI_method_set_opener ,
222ec291200Sschwarze.Fn UI_method_set_writer ,
223ec291200Sschwarze.Fn UI_method_set_flusher ,
224ec291200Sschwarze.Fn UI_method_set_reader
225ec291200Sschwarzeand
226ec291200Sschwarze.Fn UI_method_set_closer
227ec291200Sschwarzeset one of the five main methods to the given function pointer.
228ec291200Sschwarze.Pp
229ec291200Sschwarze.Fn UI_method_set_prompt_constructor
230ec291200Sschwarzesets the prompt constructor, see
231ec291200Sschwarze.Xr UI_construct_prompt 3 .
232ec291200Sschwarze.Sh RETURN VALUES
233ec291200Sschwarze.Fn UI_create_method
234ec291200Sschwarzereturns a
235ec291200Sschwarze.Vt UI_METHOD
236ec291200Sschwarzepointer on success or
237ec291200Sschwarze.Dv NULL
238ec291200Sschwarzeon error.
239ec291200Sschwarze.Pp
240ec291200Sschwarze.Fn UI_method_set_opener ,
241ec291200Sschwarze.Fn UI_method_set_writer ,
242ec291200Sschwarze.Fn UI_method_set_flusher ,
243ec291200Sschwarze.Fn UI_method_set_reader ,
244ec291200Sschwarze.Fn UI_method_set_closer ,
245ec291200Sschwarzeand
246ec291200Sschwarze.Fn UI_method_set_prompt_constructor
247ec291200Sschwarzereturn 0 on success or -1 if the given method is
248ec291200Sschwarze.Dv NULL .
249ec291200Sschwarze.Pp
250ec291200Sschwarze.Fn UI_method_get_opener ,
251ec291200Sschwarze.Fn UI_method_get_writer ,
252ec291200Sschwarze.Fn UI_method_get_flusher ,
253ec291200Sschwarze.Fn UI_method_get_reader ,
254ec291200Sschwarze.Fn UI_method_get_closer ,
255ec291200Sschwarzeand
256ec291200Sschwarze.Fn UI_method_get_prompt_constructor
257ec291200Sschwarzereturn the requested function pointer if it is set in the method,
258ec291200Sschwarzeor otherwise
259ec291200Sschwarze.Dv NULL .
260ec291200Sschwarze.Sh SEE ALSO
261ec291200Sschwarze.Xr UI_get_string_type 3 ,
262ec291200Sschwarze.Xr UI_new 3
26380d1afcdSschwarze.Sh HISTORY
26480d1afcdSschwarze.Fn UI_create_method ,
26580d1afcdSschwarze.Fn UI_destroy_method ,
26680d1afcdSschwarze.Fn UI_method_set_opener ,
26780d1afcdSschwarze.Fn UI_method_set_writer ,
26880d1afcdSschwarze.Fn UI_method_set_flusher ,
26980d1afcdSschwarze.Fn UI_method_set_reader ,
27080d1afcdSschwarze.Fn UI_method_set_closer ,
27180d1afcdSschwarze.Fn UI_method_get_opener ,
27280d1afcdSschwarze.Fn UI_method_get_writer ,
27380d1afcdSschwarze.Fn UI_method_get_flusher ,
27480d1afcdSschwarze.Fn UI_method_get_reader ,
27580d1afcdSschwarzeand
27680d1afcdSschwarze.Fn UI_method_get_closer
27780d1afcdSschwarzefirst appeared in OpenSSL 0.9.7 and have been available since
27880d1afcdSschwarze.Ox 3.2 .
27956929f71Sschwarze.Pp
28056929f71Sschwarze.Fn UI_method_set_prompt_constructor
28156929f71Sschwarzeand
28256929f71Sschwarze.Fn UI_method_get_prompt_constructor
28356929f71Sschwarzefirst appeared in OpenSSL 1.0.0 and have been available since
28456929f71Sschwarze.Ox 4.9 .
285