OSSL_ENCODER_CTX.3ossl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "OSSL_ENCODER_CTX 3ossl"
  58. .TH OSSL_ENCODER_CTX 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. OSSL_ENCODER_CTX,
  65. OSSL_ENCODER_CTX_new,
  66. OSSL_ENCODER_settable_ctx_params,
  67. OSSL_ENCODER_CTX_set_params,
  68. OSSL_ENCODER_CTX_free,
  69. OSSL_ENCODER_CTX_set_selection,
  70. OSSL_ENCODER_CTX_set_output_type,
  71. OSSL_ENCODER_CTX_set_output_structure,
  72. OSSL_ENCODER_CTX_add_encoder,
  73. OSSL_ENCODER_CTX_add_extra,
  74. OSSL_ENCODER_CTX_get_num_encoders,
  75. OSSL_ENCODER_INSTANCE,
  76. OSSL_ENCODER_INSTANCE_get_encoder,
  77. OSSL_ENCODER_INSTANCE_get_encoder_ctx,
  78. OSSL_ENCODER_INSTANCE_get_output_type,
  79. OSSL_ENCODER_INSTANCE_get_output_structure,
  80. OSSL_ENCODER_CONSTRUCT,
  81. OSSL_ENCODER_CLEANUP,
  82. OSSL_ENCODER_CTX_set_construct,
  83. OSSL_ENCODER_CTX_set_construct_data,
  84. OSSL_ENCODER_CTX_set_cleanup
  85. \&\- Encoder context routines
  86. .SH SYNOPSIS
  87. .IX Header "SYNOPSIS"
  88. .Vb 1
  89. \& #include <openssl/encoder.h>
  90. \&
  91. \& typedef struct ossl_encoder_ctx_st OSSL_ENCODER_CTX;
  92. \&
  93. \& OSSL_ENCODER_CTX *OSSL_ENCODER_CTX_new();
  94. \& const OSSL_PARAM *OSSL_ENCODER_settable_ctx_params(OSSL_ENCODER *encoder);
  95. \& int OSSL_ENCODER_CTX_set_params(OSSL_ENCODER_CTX *ctx,
  96. \& const OSSL_PARAM params[]);
  97. \& void OSSL_ENCODER_CTX_free(OSSL_ENCODER_CTX *ctx);
  98. \&
  99. \& int OSSL_ENCODER_CTX_set_selection(OSSL_ENCODER_CTX *ctx, int selection);
  100. \& int OSSL_ENCODER_CTX_set_output_type(OSSL_ENCODER_CTX *ctx,
  101. \& const char *output_type);
  102. \& int OSSL_ENCODER_CTX_set_output_structure(OSSL_ENCODER_CTX *ctx,
  103. \& const char *output_structure);
  104. \&
  105. \& int OSSL_ENCODER_CTX_add_encoder(OSSL_ENCODER_CTX *ctx, OSSL_ENCODER *encoder);
  106. \& int OSSL_ENCODER_CTX_add_extra(OSSL_ENCODER_CTX *ctx,
  107. \& OSSL_LIB_CTX *libctx, const char *propq);
  108. \& int OSSL_ENCODER_CTX_get_num_encoders(OSSL_ENCODER_CTX *ctx);
  109. \&
  110. \& typedef struct ossl_encoder_instance_st OSSL_ENCODER_INSTANCE;
  111. \& OSSL_ENCODER *
  112. \& OSSL_ENCODER_INSTANCE_get_encoder(OSSL_ENCODER_INSTANCE *encoder_inst);
  113. \& void *
  114. \& OSSL_ENCODER_INSTANCE_get_encoder_ctx(OSSL_ENCODER_INSTANCE *encoder_inst);
  115. \& const char *
  116. \& OSSL_ENCODER_INSTANCE_get_output_type(OSSL_ENCODER_INSTANCE *encoder_inst);
  117. \& const char *
  118. \& OSSL_ENCODER_INSTANCE_get_output_structure(OSSL_ENCODER_INSTANCE *encoder_inst);
  119. \&
  120. \& typedef const void *OSSL_ENCODER_CONSTRUCT(OSSL_ENCODER_INSTANCE *encoder_inst,
  121. \& void *construct_data);
  122. \& typedef void OSSL_ENCODER_CLEANUP(void *construct_data);
  123. \&
  124. \& int OSSL_ENCODER_CTX_set_construct(OSSL_ENCODER_CTX *ctx,
  125. \& OSSL_ENCODER_CONSTRUCT *construct);
  126. \& int OSSL_ENCODER_CTX_set_construct_data(OSSL_ENCODER_CTX *ctx,
  127. \& void *construct_data);
  128. \& int OSSL_ENCODER_CTX_set_cleanup(OSSL_ENCODER_CTX *ctx,
  129. \& OSSL_ENCODER_CLEANUP *cleanup);
  130. .Ve
  131. .SH DESCRIPTION
  132. .IX Header "DESCRIPTION"
  133. Encoding an input object to the desired encoding may be done with a chain of
  134. encoder implementations, which means that the output from one encoder may be
  135. the input for the next in the chain. The \fBOSSL_ENCODER_CTX\fR holds all the
  136. data about these encoders. This allows having generic format encoders such
  137. as DER to PEM, as well as more specialized encoders like RSA to DER.
  138. .PP
  139. The final output type must be given, and a chain of encoders must end with
  140. an implementation that produces that output type.
  141. .PP
  142. At the beginning of the encoding process, a constructor provided by the
  143. caller is called to ensure that there is an appropriate provider-side object
  144. to start with.
  145. The constructor is set with \fBOSSL_ENCODER_CTX_set_construct()\fR.
  146. .PP
  147. \&\fBOSSL_ENCODER_INSTANCE\fR is an opaque structure that contains data about the
  148. encoder that is going to be used, and that may be useful for the
  149. constructor. There are some functions to extract data from this type,
  150. described in "Constructor" below.
  151. .SS Functions
  152. .IX Subsection "Functions"
  153. \&\fBOSSL_ENCODER_CTX_new()\fR creates a \fBOSSL_ENCODER_CTX\fR.
  154. .PP
  155. \&\fBOSSL_ENCODER_settable_ctx_params()\fR returns an \fBOSSL_PARAM\fR\|(3)
  156. array of parameter descriptors.
  157. .PP
  158. \&\fBOSSL_ENCODER_CTX_set_params()\fR attempts to set parameters specified
  159. with an \fBOSSL_PARAM\fR\|(3) array \fIparams\fR. Parameters that the
  160. implementation doesn't recognise should be ignored.
  161. .PP
  162. \&\fBOSSL_ENCODER_CTX_free()\fR frees the given context \fIctx\fR.
  163. If the argument is NULL, nothing is done.
  164. .PP
  165. \&\fBOSSL_ENCODER_CTX_add_encoder()\fR populates the \fBOSSL_ENCODER_CTX\fR
  166. \&\fIctx\fR with a encoder, to be used to encode an input object.
  167. .PP
  168. \&\fBOSSL_ENCODER_CTX_add_extra()\fR finds encoders that further encodes output
  169. from already added encoders, and adds them as well. This is used to build
  170. encoder chains.
  171. .PP
  172. \&\fBOSSL_ENCODER_CTX_set_output_type()\fR sets the ending output type. This must
  173. be specified, and determines if a complete encoder chain is available.
  174. .PP
  175. \&\fBOSSL_ENCODER_CTX_set_output_structure()\fR sets the desired output structure.
  176. This may be used to determines what encoder implementations may be used.
  177. Depending on the type of object being encoded, the output structure may
  178. not be relevant.
  179. .PP
  180. \&\fBOSSL_ENCODER_CTX_get_num_encoders()\fR gets the number of encoders currently
  181. added to the context \fIctx\fR.
  182. .PP
  183. \&\fBOSSL_ENCODER_CTX_set_construct()\fR sets the constructor \fIconstruct\fR.
  184. .PP
  185. \&\fBOSSL_ENCODER_CTX_set_construct_data()\fR sets the constructor data that is
  186. passed to the constructor every time it's called.
  187. .PP
  188. \&\fBOSSL_ENCODER_CTX_set_cleanup()\fR sets the constructor data \fIcleanup\fR
  189. function. This is called by \fBOSSL_ENCODER_CTX_free\fR\|(3).
  190. .SS Constructor
  191. .IX Subsection "Constructor"
  192. A \fBOSSL_ENCODER_CONSTRUCT\fR gets the following arguments:
  193. .IP \fIencoder_inst\fR 4
  194. .IX Item "encoder_inst"
  195. The \fBOSSL_ENCODER_INSTANCE\fR for the encoder from which the constructor gets
  196. its data.
  197. .IP \fIconstruct_data\fR 4
  198. .IX Item "construct_data"
  199. The pointer that was set with \fBOSSL_ENCODE_CTX_set_construct_data()\fR.
  200. .PP
  201. The constructor is expected to return a valid (non-NULL) pointer to a
  202. provider-native object that can be used as first input of an encoding chain,
  203. or NULL to indicate that an error has occurred.
  204. .PP
  205. These utility functions may be used by a constructor:
  206. .PP
  207. \&\fBOSSL_ENCODER_INSTANCE_get_encoder()\fR can be used to get the encoder
  208. implementation of the encoder instance \fIencoder_inst\fR.
  209. .PP
  210. \&\fBOSSL_ENCODER_INSTANCE_get_encoder_ctx()\fR can be used to get the encoder
  211. implementation's provider context of the encoder instance \fIencoder_inst\fR.
  212. .PP
  213. \&\fBOSSL_ENCODER_INSTANCE_get_output_type()\fR can be used to get the output type
  214. for the encoder implementation of the encoder instance \fIencoder_inst\fR.
  215. This will never be NULL.
  216. .PP
  217. \&\fBOSSL_ENCODER_INSTANCE_get_output_structure()\fR can be used to get the output
  218. structure for the encoder implementation of the encoder instance
  219. \&\fIencoder_inst\fR.
  220. This may be NULL.
  221. .SH "RETURN VALUES"
  222. .IX Header "RETURN VALUES"
  223. \&\fBOSSL_ENCODER_CTX_new()\fR returns a pointer to a \fBOSSL_ENCODER_CTX\fR, or NULL
  224. if the context structure couldn't be allocated.
  225. .PP
  226. \&\fBOSSL_ENCODER_settable_ctx_params()\fR returns an \fBOSSL_PARAM\fR\|(3) array, or
  227. NULL if none is available.
  228. .PP
  229. \&\fBOSSL_ENCODER_CTX_set_params()\fR returns 1 if all recognised parameters were
  230. valid, or 0 if one of them was invalid or caused some other failure in the
  231. implementation.
  232. .PP
  233. \&\fBOSSL_ENCODER_CTX_add_encoder()\fR, \fBOSSL_ENCODER_CTX_add_extra()\fR,
  234. \&\fBOSSL_ENCODER_CTX_set_construct()\fR, \fBOSSL_ENCODER_CTX_set_construct_data()\fR and
  235. \&\fBOSSL_ENCODER_CTX_set_cleanup()\fR return 1 on success, or 0 on failure.
  236. .PP
  237. \&\fBOSSL_ENCODER_CTX_get_num_encoders()\fR returns the current number of encoders.
  238. It returns 0 if \fIctx\fR is NULL.
  239. .PP
  240. \&\fBOSSL_ENCODER_INSTANCE_get_encoder()\fR returns an \fBOSSL_ENCODER\fR pointer on
  241. success, or NULL on failure.
  242. .PP
  243. \&\fBOSSL_ENCODER_INSTANCE_get_encoder_ctx()\fR returns a provider context pointer on
  244. success, or NULL on failure.
  245. .PP
  246. \&\fBOSSL_ENCODER_INSTANCE_get_output_type()\fR returns a string with the name of the
  247. input type, if relevant. NULL is a valid returned value.
  248. .PP
  249. \&\fBOSSL_ENCODER_INSTANCE_get_output_type()\fR returns a string with the name of the
  250. output type.
  251. .PP
  252. \&\fBOSSL_ENCODER_INSTANCE_get_output_structure()\fR returns a string with the name
  253. of the output structure.
  254. .SH "SEE ALSO"
  255. .IX Header "SEE ALSO"
  256. \&\fBprovider\fR\|(7), \fBOSSL_ENCODER\fR\|(3)
  257. .SH HISTORY
  258. .IX Header "HISTORY"
  259. The functions described here were added in OpenSSL 3.0.
  260. .SH COPYRIGHT
  261. .IX Header "COPYRIGHT"
  262. Copyright 2019\-2024 The OpenSSL Project Authors. All Rights Reserved.
  263. .PP
  264. Licensed under the Apache License 2.0 (the "License"). You may not use
  265. this file except in compliance with the License. You can obtain a copy
  266. in the file LICENSE in the source distribution or at
  267. <https://www.openssl.org/source/license.html>.