1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<!-- lifted from troff+man by doclifter -->
<refentry>
<refmeta>
<refentrytitle>IPSEC_TTODATA</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo class='date'>16 August 2003</refmiscinfo>
</refmeta>
<refnamediv id='name'>
<refname>ipsec ttodata</refname>
<refname>datatot</refname>
<refpurpose>convert binary data bytes from and to text formats</refpurpose>
</refnamediv>
<!-- body begins here -->
<refsynopsisdiv id='synopsis'>
<funcsynopsis>
<funcsynopsisinfo>
#include <freeswan.h>
</funcsynopsisinfo>
<funcprototype>
<funcdef>const char *<function>ttodata</function></funcdef>
<paramdef>const char * <parameter>src</parameter></paramdef>
<paramdef>size_t <parameter>srclen</parameter></paramdef>
<paramdef>int <parameter>base</parameter></paramdef>
<paramdef>char * <parameter>dst</parameter></paramdef>
<paramdef>size_t <parameter>dstlen</parameter></paramdef>
<paramdef>size_t * <parameter>lenp</parameter></paramdef>
</funcprototype>
<funcsynopsisinfo>
</funcsynopsisinfo>
<funcprototype>
<funcdef>const char *<function>ttodatav</function></funcdef>
<paramdef>const char * <parameter>src</parameter></paramdef>
<paramdef>size_t <parameter>srclen</parameter></paramdef>
<paramdef>int <parameter>base</parameter></paramdef>
<paramdef>char * <parameter>dst</parameter></paramdef>
<paramdef>size_t <parameter>dstlen</parameter></paramdef>
<paramdef>size_t * <parameter>lenp</parameter></paramdef>
<paramdef>char * <parameter>errp</parameter></paramdef>
<paramdef>size_t <parameter>errlen</parameter></paramdef>
<paramdef>int <parameter>flags</parameter></paramdef>
</funcprototype>
<funcsynopsisinfo>
</funcsynopsisinfo>
<funcprototype>
<funcdef>size_t <function>datatot</function></funcdef>
<paramdef>const char * <parameter>src</parameter></paramdef>
<paramdef>size_t <parameter>srclen</parameter></paramdef>
<paramdef>int <parameter>format</parameter></paramdef>
<paramdef>char * <parameter>dst</parameter></paramdef>
<paramdef>size_t <parameter>dstlen</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1 id='description'><title>DESCRIPTION</title>
<para><emphasis remap='I'>Ttodata</emphasis>,
<function>ttodatav</function>,
and
<function>datatot</function>
convert arbitrary binary data (e.g. encryption or authentication keys)
from and to more-or-less human-readable text formats.</para>
<para>Currently supported formats are hexadecimal, base64, and characters.</para>
<para>A hexadecimal text value begins with a
<emphasis remap='B'>0x</emphasis>
(or
<emphasis remap='B'>0X</emphasis>)
prefix and continues with two-digit groups
of hexadecimal digits (0-9, and a-f or A-F),
each group encoding the value of one binary byte, high-order digit first.
A single
<emphasis remap='B'>_</emphasis>
(underscore)
between consecutive groups is ignored, permitting punctuation to improve
readability; doing this every eight digits seems about right.</para>
<para>A base64 text value begins with a
<emphasis remap='B'>0s</emphasis>
(or
<emphasis remap='B'>0S</emphasis>)
prefix
and continues with four-digit groups of base64 digits (A-Z, a-z, 0-9, +, and /),
each group encoding the value of three binary bytes as described in
section 6.8 of RFC 2045.
If
<varname role='parameter'>flags</varname>
has the
<emphasis remap='B'>TTODATAV_IGNORESPACE</emphasis>
bit on, blanks are ignore (after the prefix).
Note that the last one or two digits of a base64 group can be
<emphasis remap='B'>=</emphasis>
to indicate that fewer than three binary bytes are encoded.</para>
<para>A character text value begins with a
<emphasis remap='B'>0t</emphasis>
(or
<emphasis remap='B'>0T</emphasis>)
prefix
and continues with text characters, each being the value of one binary byte.</para>
<para>All these functions basically copy data from
<varname role='parameter'>src</varname>
(whose size is specified by
<varname role='parameter'>srclen</varname>)
to
<varname role='parameter'>dst</varname>
(whose size is specified by
<varname role='parameter'>dstlen</varname>),
doing the conversion en route.
If the result will not fit in
<varname role='parameter'>dst</varname>,
it is truncated;
under no circumstances are more than
<varname role='parameter'>dstlen</varname>
bytes of result written to
<varname role='parameter'>dst</varname>.
<emphasis remap='I'>Dstlen</emphasis>
can be zero, in which case
<varname role='parameter'>dst</varname>
need not be valid and no result bytes are written at all.</para>
<para>The
<varname role='parameter'>base</varname>
parameter of
<function>ttodata</function>
and
<function>ttodatav</function>
specifies what format the input is in;
normally it should be
<literal>0</literal>
to signify that this gets figured out from the prefix.
Values of
<literal>16</literal>,
<literal>64</literal>,
and
<literal>256</literal>
respectively signify hexadecimal, base64, and character-text formats
without prefixes.</para>
<para>The
<varname role='parameter'>format</varname>
parameter of
<function>datatot</function>,
a single character used as a type code,
specifies which text format is wanted.
The value
<literal>0</literal>
(not ASCII
<emphasis remap='B'>'0'</emphasis>,
but a zero value) specifies a reasonable default.
Other currently-supported values are:</para>
<!-- .RS 2 -->
<variablelist remap='TP'>
<varlistentry>
<term><emphasis remap='B'>'x'</emphasis></term>
<listitem>
<para>continuous lower-case hexadecimal with a
<emphasis remap='B'>0x</emphasis>
prefix</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis remap='B'>'h'</emphasis></term>
<listitem>
<para>lower-case hexadecimal with a
<emphasis remap='B'>0x</emphasis>
prefix and a
<emphasis remap='B'>_</emphasis>
every eight digits</para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis remap='B'>':'</emphasis></term>
<listitem>
<para>lower-case hexadecimal with no prefix and a
<emphasis remap='B'>:</emphasis>
(colon) every two digits</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>16</literal></term>
<listitem>
<para>lower-case hexadecimal with no prefix or
<emphasis remap='B'>_</emphasis></para>
</listitem>
</varlistentry>
<varlistentry>
<term><emphasis remap='B'>'s'</emphasis></term>
<listitem>
<para>continuous base64 with a
<emphasis remap='B'>0s</emphasis>
prefix</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>64</literal></term>
<listitem>
<para>continuous base64 with no prefix</para>
</listitem>
</varlistentry>
</variablelist>
<!-- .RE -->
<para>The default format is currently
<emphasis remap='B'>'h'</emphasis>.</para>
<para><emphasis remap='I'>Ttodata</emphasis>
returns NULL for success and
a pointer to a string-literal error message for failure;
see DIAGNOSTICS.
On success,
if and only if
<varname role='parameter'>lenp</varname>
is non-NULL,
<emphasis remap='B'>*lenp</emphasis>
is set to the number of bytes required to contain the full untruncated result.
It is the caller's responsibility to check this against
<varname role='parameter'>dstlen</varname>
to determine whether he has obtained a complete result.
The
<emphasis remap='B'>*lenp</emphasis>
value is correct even if
<varname role='parameter'>dstlen</varname>
is zero, which offers a way to determine how much space would be needed
before having to allocate any.</para>
<para><emphasis remap='I'>Ttodatav</emphasis>
is just like
<function>ttodata</function>
except that in certain cases,
if
<varname role='parameter'>errp</varname>
is non-NULL,
the buffer pointed to by
<varname role='parameter'>errp</varname>
(whose length is given by
<varname role='parameter'>errlen</varname>)
is used to hold a more detailed error message.
The return value is NULL for success,
and is either
<varname role='parameter'>errp</varname>
or a pointer to a string literal for failure.
If the size of the error-message buffer is
inadequate for the desired message,
<function>ttodatav</function>
will fall back on returning a pointer to a literal string instead.
The
<emphasis remap='I'>freeswan.h</emphasis>
header file defines a constant
<emphasis remap='B'>TTODATAV_BUF</emphasis>
which is the size of a buffer large enough for worst-case results.</para>
<para>The normal return value of
<function>datatot</function>
is the number of bytes required
to contain the full untruncated result.
It is the caller's responsibility to check this against
<varname role='parameter'>dstlen</varname>
to determine whether he has obtained a complete result.
The return value is correct even if
<varname role='parameter'>dstlen</varname>
is zero, which offers a way to determine how much space would be needed
before having to allocate any.
A return value of
<literal>0</literal>
signals a fatal error of some kind
(see DIAGNOSTICS).</para>
<para>A zero value for
<varname role='parameter'>srclen</varname>
in
<function>ttodata</function>
(but not
<function>datatot</function>!)
is synonymous with
<emphasis remap='B'>strlen(src)</emphasis>.
A non-zero
<varname role='parameter'>srclen</varname>
in
<function>ttodata</function>
must not include the terminating NUL.</para>
<para>Unless
<varname role='parameter'>dstlen</varname>
is zero,
the result supplied by
<function>datatot</function>
is always NUL-terminated,
and its needed-size return value includes space for the terminating NUL.</para>
<para>Several obsolete variants of these functions
(<emphasis remap='I'>atodata</emphasis>,
<emphasis remap='I'>datatoa</emphasis>,
<emphasis remap='I'>atobytes</emphasis>,
and
<emphasis remap='I'>bytestoa</emphasis>)
are temporarily also supported.</para>
</refsect1>
<refsect1 id='see_also'><title>SEE ALSO</title>
<para><citerefentry><refentrytitle>sprintf</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>ipsec_atoaddr</refentrytitle><manvolnum>3</manvolnum></citerefentry></para>
</refsect1>
<refsect1 id='diagnostics'><title>DIAGNOSTICS</title>
<para>Fatal errors in
<function>ttodata</function>
and
<function>ttodatav</function>
are:
unknown characters in the input;
unknown or missing prefix;
unknown base;
incomplete digit group;
non-zero padding in a base64 less-than-three-bytes digit group;
zero-length input.</para>
<para>Fatal errors in
<function>datatot</function>
are:
unknown format code;
zero-length input.</para>
</refsect1>
<refsect1 id='history'><title>HISTORY</title>
<para>Written for the FreeS/WAN project by Henry Spencer.</para>
</refsect1>
<refsect1 id='bugs'><title>BUGS</title>
<para><emphasis remap='I'>Datatot</emphasis>
should have a format code to produce character-text output.</para>
<para>The
<emphasis remap='B'>0s</emphasis>
and
<emphasis remap='B'>0t</emphasis>
prefixes are the author's inventions and are not a standard
of any kind.
They have been chosen to avoid collisions with existing practice
(some C implementations use
<emphasis remap='B'>0b</emphasis>
for binary)
and possible confusion with unprefixed hexadecimal.</para>
</refsect1>
</refentry>
|