diff options
author | schwarze <> | 2018-02-12 15:45:12 +0000 |
---|---|---|
committer | schwarze <> | 2018-02-12 15:45:12 +0000 |
commit | 07fd0d6c60438241a541e714655b2213e0617433 (patch) | |
tree | dd86a4e7e1102496146be36c951908c0df779b8a | |
parent | 95150ccab60dc90f32fc3d09c09ba1af1ad6a112 (diff) | |
download | openbsd-07fd0d6c60438241a541e714655b2213e0617433.tar.gz openbsd-07fd0d6c60438241a541e714655b2213e0617433.tar.bz2 openbsd-07fd0d6c60438241a541e714655b2213e0617433.zip |
Add the missing RETURN VALUES section and reorder the content
accordingly. Make some statements more precise, and point out
some dangerous traps in these ill-designed interfaces.
Also do some minor polishing while here.
Triggered by OpenSSL commit 1f13ad31 Dec 25 17:50:39 2017 +0800
by Paul Yang, but not using most of his wording because that is in
part redundant, in part incomplete, and in part outright wrong.
-rw-r--r-- | src/lib/libcrypto/man/ASN1_STRING_length.3 | 128 |
1 files changed, 93 insertions, 35 deletions
diff --git a/src/lib/libcrypto/man/ASN1_STRING_length.3 b/src/lib/libcrypto/man/ASN1_STRING_length.3 index 2c797481d7..398d49eee4 100644 --- a/src/lib/libcrypto/man/ASN1_STRING_length.3 +++ b/src/lib/libcrypto/man/ASN1_STRING_length.3 | |||
@@ -1,8 +1,26 @@ | |||
1 | .\" $OpenBSD: ASN1_STRING_length.3,v 1.6 2016/12/25 22:15:10 schwarze Exp $ | 1 | .\" $OpenBSD: ASN1_STRING_length.3,v 1.7 2018/02/12 15:45:12 schwarze Exp $ |
2 | .\" OpenSSL 99d63d46 Tue Jun 21 07:03:34 2016 -0400 | 2 | .\" full merge up to: OpenSSL 99d63d46 Tue Jun 21 07:03:34 2016 -0400 |
3 | .\" selective merge up to: OpenSSL 61f805c1 Jan 16 01:01:46 2018 +0800 | ||
3 | .\" | 4 | .\" |
4 | .\" This file was written by Dr. Stephen Henson. | 5 | .\" This file is a derived work. |
5 | .\" Copyright (c) 2002, 2006, 2013, 2015, 2016 The OpenSSL Project. | 6 | .\" The changes are covered by the following Copyright and license: |
7 | .\" | ||
8 | .\" Copyright (c) 2018 Ingo Schwarze <schwarze@openbsd.org> | ||
9 | .\" | ||
10 | .\" Permission to use, copy, modify, and distribute this software for any | ||
11 | .\" purpose with or without fee is hereby granted, provided that the above | ||
12 | .\" copyright notice and this permission notice appear in all copies. | ||
13 | .\" | ||
14 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
15 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
16 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
17 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
18 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
19 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
20 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
21 | .\" | ||
22 | .\" The original file was written by Dr. Stephen Henson. | ||
23 | .\" Copyright (c) 2002, 2006, 2013, 2015, 2016, 2017 The OpenSSL Project. | ||
6 | .\" All rights reserved. | 24 | .\" All rights reserved. |
7 | .\" | 25 | .\" |
8 | .\" Redistribution and use in source and binary forms, with or without | 26 | .\" Redistribution and use in source and binary forms, with or without |
@@ -49,7 +67,7 @@ | |||
49 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 67 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
50 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. | 68 | .\" OF THE POSSIBILITY OF SUCH DAMAGE. |
51 | .\" | 69 | .\" |
52 | .Dd $Mdocdate: December 25 2016 $ | 70 | .Dd $Mdocdate: February 12 2018 $ |
53 | .Dt ASN1_STRING_LENGTH 3 | 71 | .Dt ASN1_STRING_LENGTH 3 |
54 | .Os | 72 | .Os |
55 | .Sh NAME | 73 | .Sh NAME |
@@ -107,27 +125,24 @@ These functions manipulate | |||
107 | structures. | 125 | structures. |
108 | .Pp | 126 | .Pp |
109 | .Fn ASN1_STRING_cmp | 127 | .Fn ASN1_STRING_cmp |
110 | compares | 128 | compares the type, the length, and the content of |
111 | .Fa a | 129 | .Fa a |
112 | and | 130 | and |
113 | .Fa b | 131 | .Fa b . |
114 | and returns 0 if the two are identical. | ||
115 | The string types and the content are compared. | ||
116 | .Pp | 132 | .Pp |
117 | .Fn ASN1_STRING_data | 133 | .Fn ASN1_STRING_data |
118 | returns an internal pointer to the data of | 134 | returns an internal pointer to the data of |
119 | .Fa x . | 135 | .Fa x . |
120 | Since this is an internal pointer, it should | 136 | It should not be freed or modified in any way. |
121 | .Em not | ||
122 | be freed or modified in any way. | ||
123 | .Pp | 137 | .Pp |
124 | .Fn ASN1_STRING_dup | 138 | .Fn ASN1_STRING_dup |
125 | returns a copy of the structure | 139 | copies |
126 | .Fa a . | 140 | .Fa a . |
127 | .Pp | 141 | .Pp |
128 | .Fn ASN1_STRING_length | 142 | .Fn ASN1_STRING_length |
129 | returns the length of the content of | 143 | returns the length attribute of |
130 | .Fa x . | 144 | .Fa x , |
145 | measured in bytes. | ||
131 | .Pp | 146 | .Pp |
132 | .Fn ASN1_STRING_length_set | 147 | .Fn ASN1_STRING_length_set |
133 | sets the length attribute of | 148 | sets the length attribute of |
@@ -139,39 +154,46 @@ It may put | |||
139 | into an inconsistent internal state. | 154 | into an inconsistent internal state. |
140 | .Pp | 155 | .Pp |
141 | .Fn ASN1_STRING_set | 156 | .Fn ASN1_STRING_set |
142 | sets the data of the string | 157 | sets the length attribute of |
143 | .Fa str | 158 | .Fa str |
144 | to the buffer | 159 | to |
160 | .Fa len | ||
161 | and copies that number of bytes from | ||
145 | .Fa data | 162 | .Fa data |
146 | of length | 163 | into |
164 | .Fa str . | ||
165 | If | ||
166 | .Fa len | ||
167 | is -1, then | ||
168 | .Fn strlen data | ||
169 | is used instead of | ||
147 | .Fa len . | 170 | .Fa len . |
148 | The supplied data is copied. | ||
149 | If | 171 | If |
172 | .Fa data | ||
173 | is | ||
174 | .Dv NULL , | ||
175 | the content of | ||
176 | .Fa str | ||
177 | remains uninitialized; that is not considered an error unless | ||
150 | .Fa len | 178 | .Fa len |
151 | is -1 then the length is determined by | 179 | is negative. |
152 | .Fn strlen data . | ||
153 | .Pp | 180 | .Pp |
154 | .Fn ASN1_STRING_to_UTF8 | 181 | .Fn ASN1_STRING_to_UTF8 |
155 | converts the string | 182 | converts the string |
156 | .Fa in | 183 | .Fa in |
157 | to UTF8 format. | 184 | to UTF-8 format. |
158 | The converted data is copied into a newly allocated buffer | 185 | The converted data is copied into a newly allocated buffer |
159 | .Fa out . | 186 | .Pf * Fa out . |
160 | The length of | ||
161 | .Fa out | ||
162 | is returned or a negative error code. | ||
163 | The buffer | 187 | The buffer |
164 | .Fa out | 188 | .Pf * Fa out |
165 | should be freed using | 189 | should be freed using |
166 | .Xr free 3 . | 190 | .Xr free 3 . |
167 | .Pp | 191 | .Pp |
168 | .Fn ASN1_STRING_type | 192 | .Fn ASN1_STRING_type |
169 | returns the type of | 193 | returns the type of |
170 | .Fa x , | 194 | .Fa x . |
171 | using standard constants such as | ||
172 | .Dv V_ASN1_OCTET_STRING . | ||
173 | .Pp | 195 | .Pp |
174 | Almost all ASN.1 types in OpenSSL are represented as | 196 | Almost all ASN.1 types are represented as |
175 | .Vt ASN1_STRING | 197 | .Vt ASN1_STRING |
176 | structures. | 198 | structures. |
177 | Other types such as | 199 | Other types such as |
@@ -200,17 +222,53 @@ be used instead. | |||
200 | In general it cannot be assumed that the data returned by | 222 | In general it cannot be assumed that the data returned by |
201 | .Fn ASN1_STRING_data | 223 | .Fn ASN1_STRING_data |
202 | is NUL terminated, and it may contain embedded NUL characters. | 224 | is NUL terminated, and it may contain embedded NUL characters. |
203 | The actual format of the data will depend on the actual string type itself: | 225 | The format of the data depends on the string type: |
204 | for example for an | 226 | for example for an |
205 | .Vt IA5String | 227 | .Vt IA5String |
206 | the data will be ASCII, for a | 228 | the data contains ASCII characters, a |
207 | .Vt BMPString | 229 | .Vt BMPString |
208 | two bytes per character in big endian format, and a | 230 | two bytes per character in big endian format, and a |
209 | .Vt UTF8String | 231 | .Vt UTF8String |
210 | will be in UTF8 format. | 232 | UTF-8 characters. |
211 | .Pp | 233 | .Pp |
212 | Similar care should be take to ensure the data is in the correct format | 234 | Similar care should be taken to ensure the data is in the correct format |
213 | when calling | 235 | when calling |
214 | .Fn ASN1_STRING_set . | 236 | .Fn ASN1_STRING_set . |
237 | .Sh RETURN VALUES | ||
238 | .Fn ASN1_STRING_cmp | ||
239 | returns 0 if the type, the length, and the content of | ||
240 | .Fa a | ||
241 | and | ||
242 | .Fa b | ||
243 | agree, or a non-zero value otherwise. | ||
244 | In contrast to | ||
245 | .Xr strcmp 3 , | ||
246 | the sign of the return value does not indicate lexicographical ordering. | ||
247 | .Pp | ||
248 | .Fn ASN1_STRING_data | ||
249 | returns an internal pointer to the data of | ||
250 | .Fa x . | ||
251 | .Pp | ||
252 | .Fn ASN1_STRING_dup | ||
253 | returns a pointer to a newly allocated | ||
254 | .Vt ASN1_STRING | ||
255 | structure or | ||
256 | .Dv NULL | ||
257 | if an error occurred. | ||
258 | .Pp | ||
259 | .Fn ASN1_STRING_length | ||
260 | returns a number of bytes. | ||
261 | .Pp | ||
262 | .Fn ASN1_STRING_set | ||
263 | returns 1 on success or 0 on failure. | ||
264 | .Pp | ||
265 | .Fn ASN1_STRING_to_UTF8 | ||
266 | returns the number of bytes in the output buffer | ||
267 | .Pf * Fa out , | ||
268 | or a negative number if an error occurred. | ||
269 | .Pp | ||
270 | .Fn ASN1_STRING_type | ||
271 | returns an integer constant, for example | ||
272 | .Dv V_ASN1_OCTET_STRING . | ||
215 | .Sh SEE ALSO | 273 | .Sh SEE ALSO |
216 | .Xr ERR_get_error 3 | 274 | .Xr ERR_get_error 3 |