Eneboo - Documentación para desarrolladores
src/libdigidoc/DigiDocConvert.h
Ir a la documentación de este archivo.
00001 #ifndef __DIGIDOC_CONVERT_H__
00002 #define __DIGIDOC_CONVERT_H__
00003 //==================================================
00004 // FILE:        DigiDocEnc.h
00005 // PROJECT:     Digi Doc Encryption
00006 // DESCRIPTION: DigiDoc character conversion routines
00007 // AUTHOR:  Veiko Sinivee, S|E|B IT Partner Estonia
00008 //==================================================
00009 // Copyright (C) AS Sertifitseerimiskeskus
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Lesser General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2.1 of the License, or (at your option) any later version.
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 // GNU Lesser General Public Licence is available at
00019 // http://www.gnu.org/copyleft/lesser.html
00020 //==========< HISTORY >=============================
00021 //      22.09.2004      Veiko Sinivee
00022 //                      Creation
00023 //==================================================
00024 
00025 #include <libdigidoc/DigiDocLib.h>
00026 #include <libdigidoc/DigiDocDefs.h>
00027 
00028 #ifdef  __cplusplus
00029 extern "C" {
00030 #endif
00031 
00032 //==========< general functions >============
00033 
00034 //--------------------------------------------------
00035 // Decodes a single hex digit
00036 // h - hex digit
00037 // return binary value
00038 //--------------------------------------------------
00039 byte h2b(char h);
00040 
00041 //--------------------------------------------------
00042 // Converts a single byte to two hex characters
00043 // b - binary value
00044 // dest - destination buffer
00045 //--------------------------------------------------
00046 void b2h(byte b, char* dest);
00047 
00048 //--------------------------------------------------
00049 // Converts correct filename to incorrect encoding
00050 // used in formats 1.0, 1.1 and 1.2
00051 // src - input data
00052 // dest - buffer for converted data
00053 // len - length of destination buffer
00054 //--------------------------------------------------
00055 EXP_OPTION void convFNameToWin(const char* src, char* dest, int len);
00056 
00057 //--------------------------------------------------
00058 // Converts bad UTF-8 filename used in formats 1.0, 
00059 // 1.1 and 1.2 to correct encoding
00060 // src - input data
00061 // dest - buffer for converted data
00062 // len - length of destination buffer
00063 //--------------------------------------------------
00064 EXP_OPTION void convWinToFName(const char* src, char* dest, int len);
00065 
00066 // Converts a hex number (string) to binary value
00067 EXP_OPTION void hex2bin(const char* hex, byte* bin, int* len);
00068 
00069 // Converts a binary value to hex string
00070 EXP_OPTION void bin2hex(const byte* bin, int blen, char* hex, int* len);
00071 
00072 // Helper function that converts ISO Latin1 to UTF8
00073 EXP_OPTION char* ascii2utf8(const char* ascii, char* utf8out, int* outlen);
00074 
00075 // Helper function that converts UTF8 to ISO Latin1
00076 EXP_OPTION char* utf82ascii(const char* utf8in, char* asciiout, int* outlen);
00077 
00078 // converts string from unicode to ascii
00079 EXP_OPTION void unicode2ascii(const char* uni, char* dest);
00080 // converts unicode escapes string to UTF8
00081 EXP_OPTION void unicodeEscapes2utf8(const char* uni, char* dest);
00082 
00083 // replaces xml special symbols with escapes
00084 int escapeXMLSymbols(const char* src, int srclen, char** dest);
00085 int hasUmlauts(const char* str);
00086 int str2asn1time(const SignedDoc* pSigDoc, const char* str, ASN1_GENERALIZEDTIME* asn1tm);
00087 
00088 //--------------------------------------------------
00089 // Converts xml symbols to corresponding escapes
00090 // src - string with xml special sybols
00091 // returns string with esacpes
00092 //--------------------------------------------------
00093 char* escape2xmlsym(const char* src);
00094 
00095 //--------------------------------------------------
00096 // Converts input data to UTF-8
00097 // src - input data
00098 // returns converted string or NULL. Caller must free it.
00099 //--------------------------------------------------
00100 EXP_OPTION int ddocConvertInput(const char* src, char** dest);
00101 
00102 // Base64 encode some data
00103 EXP_OPTION void encode(const byte* raw, int rawlen, byte* buf, int* buflen);
00104 // Base64 decode some data
00105 EXP_OPTION void decode(const byte* raw, int rawlen, byte* buf, int* buflen);
00106 
00107 
00108 //============================================================
00109 // Decodes input data in Base64 format.
00110 // pMBufSrc - input data
00111 // pMBufDest - destination buffer
00112 //============================================================
00113 EXP_OPTION int ddocDecodeBase64(DigiDocMemBuf* pMBufSrc, DigiDocMemBuf* pMBufDest);
00114 
00115 //============================================================
00116 // Decodes input data in Base64 format.
00117 // data - input data
00118 // len - length of input data. Use -1 for zero terminated strings
00119 // pMBufDest - destination buffer
00120 //============================================================
00121 EXP_OPTION int ddocDecodeBase64Data(void* data, long lLen, DigiDocMemBuf* pMBufDest);
00122 
00123 //============================================================
00124 // Encodes input data in Base64 format.
00125 // pMBufSrc - input data
00126 // pMBufDest - destination buffer
00127 //============================================================
00128 EXP_OPTION int ddocEncodeBase64(const DigiDocMemBuf* pMBufSrc, DigiDocMemBuf* pMBufDest);
00129 
00130 //=======< time convesrion >=======================
00131 
00132 //--------------------------------------------------
00133 // Decodes an ASN1 generalized time
00134 // tm - ASN1 generalized time
00135 // y - year
00136 // M - month
00137 // d - day of month
00138 // h - hour
00139 // m - minute
00140 // s - second
00141 // returns error code or ERR_OK
00142 //--------------------------------------------------
00143 int decodeGeneralizedTime(ASN1_GENERALIZEDTIME *tm, 
00144                            int* y, int* M, int* d, 
00145                           int* h, int* m, int* s);
00146 
00147 //--------------------------------------------------
00148 // Decodes an ASN1 UTC time
00149 // tm - ASN1 generalized time
00150 // y - year
00151 // M - month
00152 // d - day of month
00153 // h - hour
00154 // m - minute
00155 // s - second
00156 // returns error code or ERR_OK
00157 //--------------------------------------------------
00158 int decodeUTCTime(ASN1_UTCTIME *tm, 
00159                   int* y, int* M, int* d, 
00160                   int* h, int* m, int* s);
00161 
00162 //==========================================================
00163 // converts ASN1 time to time_t
00164 //==========================================================
00165 int asn1time2time_t(ASN1_TIME* tm, time_t* pT);
00166 
00167 int asn1time2time_t_local(ASN1_TIME* tm, time_t* pT);
00168 
00169 //==========================================================
00170 // converts ASN1 time to string
00171 //==========================================================
00172 int asn1time2strYear(const SignedDoc* pSigDoc, ASN1_TIME* tm, char* buf, int year, int len);
00173 
00174 //==========================================================
00175 // converts ASN1 time to string
00176 //==========================================================
00177 int asn1time2str(const SignedDoc* pSigDoc, ASN1_TIME* tm, char* buf, int len);
00178 
00179 //===================================================================
00180 // converts time_t to timestamp string
00181 // t - time_t input value
00182 // szTimestamp - output buffer
00183 // len - length of buffer
00184 // returns error code or ERR_OK
00185 //===================================================================
00186   EXP_OPTION int time_t2str(time_t t, char* szTimestamp, int len);
00187 
00188 //==========< only win32 fucntions >============
00189 
00190 #ifdef WIN32
00191 
00192 //--------------------------------------------------
00193 // Converts input OEM charset data to 16 bit unicode.
00194 // oem - 8 bit oem charset input data
00195 // unicode - address of pointer for allocated unicode string. Caller must free() !
00196 // outlen - address of length variable for unicode string
00197 // returns error code or ERR_OK
00198 //--------------------------------------------------
00199 EXP_OPTION int oem2unicode(const char* oem, char** unicode, int* outlen);
00200 
00201 //--------------------------------------------------
00202 // Converts input 16 bit unicode data to UTF8.
00203 // unicode - 16 bit unicode input data
00204 // utf8 - address of pointer for allocated utf8 string. Caller must free() !
00205 // outlen - address of length variable for utf8 string
00206 // returns error code or ERR_OK
00207 //--------------------------------------------------
00208 EXP_OPTION int unicode2utf8(const char* unicode, char** utf8, int* outlen);
00209 
00210 //--------------------------------------------------
00211 // Converts input OEM charset data to UTF-8
00212 // oem - 8 bit oem charset input data
00213 // utf8 - address of buffer allocated utf8 string. 
00214 // len - size of buffer
00215 // returns error code or ERR_OK
00216 //--------------------------------------------------
00217 EXP_OPTION int oem2utf8(const char* oem, char* utf8, int len);
00218 
00219 //--------------------------------------------------
00220 // Converts input UTF-8 data to 16 bit unicode data.
00221 // utf8 - UTF-8 input data
00222 // unicode - address of pointer for allocated unicode string. Caller must free() !
00223 // outlen - address of length variable for unicode string
00224 // returns error code or ERR_OK
00225 //--------------------------------------------------
00226 EXP_OPTION int utf82unicode(const char* utf8, char** unicode, int* outlen);
00227 
00228 //--------------------------------------------------
00229 // Converts input 16 bit unicode data to oem charset data.
00230 // unicode - 16 bit unicode input data
00231 // oem - address of pointer for allocated oem string. Caller must free() !
00232 // outlen - address of length variable for oem string
00233 // returns error code or ERR_OK
00234 //--------------------------------------------------
00235 EXP_OPTION int unicode2oem(const char* unicode, char** oem, int* outlen);
00236 
00237 //--------------------------------------------------
00238 // Converts input UTF-8 data to OEM charset data
00239 // utf8 - UTF-8 input data
00240 // oem - address of buffer for oem string. 
00241 // len - size of buffer
00242 // returns error code or ERR_OK
00243 //--------------------------------------------------
00244 EXP_OPTION int utf82oem(const char* utf8, char* oem, int len);
00245 
00246 //--------------------------------------------------
00247 // Converts input UTF-8 data to OEM charset data
00248 // pSigDoc - signed doc object
00249 // pDf - data file obejct 
00250 // outFileName - output buffer
00251 // len - length of output buffer
00252 // returns error code or ERR_OK
00253 //--------------------------------------------------
00254 EXP_OPTION int getDataFileFileName(SignedDoc* pSigDoc, DataFile* pDf, char* outFileName, int len);
00255 
00256 //--------------------------------------------------
00257 // Converts a filename according to platform rules
00258 // dest - destination buffer
00259 // destlen - destination buffer length
00260 // src - source filename
00261 // returns error code or ERR_OK
00262 //--------------------------------------------------
00263 EXP_OPTION int ddocConvertFileName(char* dest, int destlen, const char* src);
00264 
00265 //--------------------------------------------------
00266 // Releases mem-block allocated by lib. In win32
00267 // this must be done since the mem was allocated by dll
00268 // and must also be released by dll that allocated it.
00269 // p - mem to be freed
00270 //--------------------------------------------------
00271 EXP_OPTION void freeLibMem(void* p);
00272 
00273 #endif // WIN32
00274 
00275 #ifdef  __cplusplus
00276 }
00277 #endif
00278 
00279 
00280 #endif // __DIGIDOC_CONVERT_H__
00281 
00282 
00283 
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'