📄 ttodata.3
字号:
.TH IPSEC_TTODATA 3 "16 August 2003".\" RCSID $Id: ttodata.3,v 1.8 2004/04/09 18:00:37 mcr Exp $.SH NAMEipsec ttodata, datatot \- convert binary data bytes from and to text formats.SH SYNOPSIS.B "#include <freeswan.h>".sp.B "const char *ttodata(const char *src, size_t srclen,".ti +1c.B "int base, char *dst, size_t dstlen, size_t *lenp);".br.B "const char *ttodatav(const char *src, size_t srclen,".ti +1c.B "int base, char *dst, size_t dstlen, size_t *lenp,".ti +1c.B "char *errp, size_t errlen, int flags);".br.B "size_t datatot(const char *src, size_t srclen,".ti +1c.B "int format, char *dst, size_t dstlen);".SH DESCRIPTION.IR Ttodata ,.IR ttodatav ,and.I datatotconvert arbitrary binary data (e.g. encryption or authentication keys)from and to more-or-less human-readable text formats..PPCurrently supported formats are hexadecimal, base64, and characters..PPA hexadecimal text value begins with a.B 0x(or.BR 0X )prefix and continues with two-digit groupsof 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.B _(underscore)between consecutive groups is ignored, permitting punctuation to improve readability; doing this every eight digits seems about right..PPA base64 text value begins with a.B 0s(or.BR 0S )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 insection 6.8 of RFC 2045.If.B flagshas the.B TTODATAV_IGNORESPACEbit on, blanks are ignore (after the prefix).Note that the last one or two digits of a base64 group can be.B =to indicate that fewer than three binary bytes are encoded..PPA character text value begins with a.B 0t(or.BR 0T )prefixand continues with text characters, each being the value of one binary byte. .PPAll these functions basically copy data from.I src(whose size is specified by.IR srclen )to.I dst(whose size is specified by.IR dstlen ),doing the conversion en route.If the result will not fit in.IR dst ,it is truncated;under no circumstances are more than.I dstlenbytes of result written to.IR dst ..I Dstlencan be zero, in which case.I dstneed not be valid and no result bytes are written at all..PPThe.I baseparameter of.I ttodataand.I ttodatavspecifies what format the input is in;normally it should be.B 0to signify that this gets figured out from the prefix.Values of.BR 16 ,.BR 64 ,and.BR 256respectively signify hexadecimal, base64, and character-text formatswithout prefixes..PPThe.I formatparameter of.IR datatot ,a single character used as a type code,specifies which text format is wanted.The value.B 0(not ASCII.BR '0' ,but a zero value) specifies a reasonable default.Other currently-supported values are:.RS 2.TP 4.B 'x'continuous lower-case hexadecimal with a.B 0xprefix.TP.B 'h'lower-case hexadecimal with a.B 0xprefix and a.B _every eight digits.TP.B ':'lower-case hexadecimal with no prefix and a.B :(colon) every two digits.TP.B 16lower-case hexadecimal with no prefix or.B _.TP.B 's'continuous base64 with a.B 0sprefix.TP.B 64continuous base64 with no prefix.RE.PPThe default format is currently.BR 'h' ..PP.I Ttodatareturns NULL for success anda pointer to a string-literal error message for failure;see DIAGNOSTICS.On success,if and only if.I lenpis non-NULL,.B *lenpis set to the number of bytes required to contain the full untruncated result.It is the caller's responsibility to check this against.I dstlento determine whether he has obtained a complete result.The.B *lenpvalue is correct even if.I dstlenis zero, which offers a way to determine how much space would be neededbefore having to allocate any..PP.I Ttodatavis just like.I ttodataexcept that in certain cases,if.I errpis non-NULL,the buffer pointed to by.I errp(whose length is given by.IR errlen )is used to hold a more detailed error message.The return value is NULL for success,and is either.I errpor a pointer to a string literal for failure.If the size of the error-message buffer isinadequate for the desired message,.I ttodatavwill fall back on returning a pointer to a literal string instead.The.I freeswan.hheader file defines a constant.B TTODATAV_BUFwhich is the size of a buffer large enough for worst-case results..PPThe normal return value of.IR datatotis the number of bytes requiredto contain the full untruncated result.It is the caller's responsibility to check this against.I dstlento determine whether he has obtained a complete result.The return value is correct even if.I dstlenis zero, which offers a way to determine how much space would be neededbefore having to allocate any.A return value of.B 0signals a fatal error of some kind(see DIAGNOSTICS)..PPA zero value for.I srclenin.I ttodata(but not.IR datatot !)is synonymous with.BR strlen(src) .A non-zero.I srclenin.I ttodatamust not include the terminating NUL..PPUnless.I dstlenis zero,the result supplied by.I datatotis always NUL-terminated,and its needed-size return value includes space for the terminating NUL..PPSeveral obsolete variants of these functions.RI ( atodata ,.IR datatoa ,.IR atobytes ,and.IR bytestoa )are temporarily also supported..SH SEE ALSOsprintf(3), ipsec_atoaddr(3).SH DIAGNOSTICSFatal errors in.I ttodataand.I ttodatavare: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..PPFatal errors in.I datatotare:unknown format code;zero-length input..SH HISTORYWritten for the FreeS/WAN project by Henry Spencer..SH BUGS.I Datatotshould have a format code to produce character-text output..PPThe.B 0sand.B 0tprefixes are the author's inventions and are not a standardof any kind.They have been chosen to avoid collisions with existing practice(some C implementations use.B 0bfor binary)and possible confusion with unprefixed hexadecimal.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -