Estonian ID Card C-library
Loading...
Searching...
No Matches
DigiDocConvert.h
1#ifndef __DIGIDOC_CONVERT_H__
2#define __DIGIDOC_CONVERT_H__
3//==================================================
4// FILE: DigiDocEnc.h
5// PROJECT: Digi Doc Encryption
6// DESCRIPTION: DigiDoc character conversion routines
7// AUTHOR: Veiko Sinivee, S|E|B IT Partner Estonia
8//==================================================
9// Copyright (C) AS Sertifitseerimiskeskus
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18// GNU Lesser General Public Licence is available at
19// http://www.gnu.org/copyleft/lesser.html
20//==========< HISTORY >=============================
21// 22.09.2004 Veiko Sinivee
22// Creation
23//==================================================
24
25#include <libdigidoc/DigiDocLib.h>
26#include <libdigidoc/DigiDocDefs.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32//==========< general functions >============
33
34//--------------------------------------------------
35// Decodes a single hex digit
36// h - hex digit
37// return binary value
38//--------------------------------------------------
39byte h2b(char h);
40
41//--------------------------------------------------
42// Converts a single byte to two hex characters
43// b - binary value
44// dest - destination buffer
45//--------------------------------------------------
46void b2h(byte b, char* dest);
47
48//--------------------------------------------------
49// Converts correct filename to incorrect encoding
50// used in formats 1.0, 1.1 and 1.2
51// src - input data
52// dest - buffer for converted data
53// len - length of destination buffer
54//--------------------------------------------------
55EXP_OPTION void convFNameToWin(const char* src, char* dest, int len);
56
57//--------------------------------------------------
58// Converts bad UTF-8 filename used in formats 1.0,
59// 1.1 and 1.2 to correct encoding
60// src - input data
61// dest - buffer for converted data
62// len - length of destination buffer
63//--------------------------------------------------
64EXP_OPTION void convWinToFName(const char* src, char* dest, int len);
65
66// Converts a hex number (string) to binary value
67EXP_OPTION void hex2bin(const char* hex, byte* bin, int* len);
68
69// Converts a binary value to hex string
70EXP_OPTION void bin2hex(const byte* bin, int blen, char* hex, int* len);
71
72//============================================================
73// Encodes input data in hex format.
74// pMBufSrc - input data
75// pMBufDest - destination buffer
76//============================================================
77EXP_OPTION int ddocBin2Hex(const DigiDocMemBuf* pMBufSrc, DigiDocMemBuf* pMBufDest);
78
79// Helper function that converts ISO Latin1 to UTF8
80EXP_OPTION char* ascii2utf8(const char* ascii, char* utf8out, int* outlen);
81
82// Helper function that converts UTF8 to ISO Latin1
83EXP_OPTION char* utf82ascii(const char* utf8in, char* asciiout, int* outlen);
84
85// converts string from unicode to ascii
86EXP_OPTION void unicode2ascii(const char* uni, char* dest);
87// converts unicode escapes string to UTF8
88EXP_OPTION void unicodeEscapes2utf8(const char* uni, char* dest);
89
90
91char* escape2xmlsym(const char* src);
92
93
94int hasUmlauts(const char* str);
95int str2asn1time(const SignedDoc* pSigDoc, const char* str, ASN1_GENERALIZEDTIME* asn1tm);
96
97//--------------------------------------------------
98// Converts xml symbols to corresponding escapes
99// src - string with xml special sybols
100// returns string with esacpes
101//--------------------------------------------------
102char* escape2xmlsym(const char* src);
103
104char* unescapeXmlsym(const char* src);
105
106//--------------------------------------------------
107// Converts input data to UTF-8
108// src - input data
109// returns converted string or NULL. Caller must free it.
110//--------------------------------------------------
111EXP_OPTION int ddocConvertInput(const char* src, char** dest);
112
113// Base64 encode some data
114EXP_OPTION void encode(const byte* raw, int rawlen, byte* buf, int* buflen);
115// Base64 decode some data
116EXP_OPTION void decode(const byte* raw, int rawlen, byte* buf, int* buflen);
117
118
119//============================================================
120// Decodes input data in Base64 format.
121// pMBufSrc - input data
122// pMBufDest - destination buffer
123//============================================================
124EXP_OPTION int ddocDecodeBase64(DigiDocMemBuf* pMBufSrc, DigiDocMemBuf* pMBufDest);
125
126//============================================================
127// Decodes input data in Base64 format.
128// data - input data
129// len - length of input data. Use -1 for zero terminated strings
130// pMBufDest - destination buffer
131//============================================================
132EXP_OPTION int ddocDecodeBase64Data(void* data, long lLen, DigiDocMemBuf* pMBufDest);
133
134//============================================================
135// Encodes input data in Base64 format.
136// pMBufSrc - input data
137// pMBufDest - destination buffer
138//============================================================
139EXP_OPTION int ddocEncodeBase64(const DigiDocMemBuf* pMBufSrc, DigiDocMemBuf* pMBufDest);
140
141//=======< time convesrion >=======================
142
143//--------------------------------------------------
144// Decodes an ASN1 generalized time
145// tm - ASN1 generalized time
146// y - year
147// M - month
148// d - day of month
149// h - hour
150// m - minute
151// s - second
152// returns error code or ERR_OK
153//--------------------------------------------------
154int decodeGeneralizedTime(ASN1_GENERALIZEDTIME *tm,
155 int* y, int* M, int* d,
156 int* h, int* m, int* s);
157
158//--------------------------------------------------
159// Decodes an ASN1 UTC time
160// tm - ASN1 generalized time
161// y - year
162// M - month
163// d - day of month
164// h - hour
165// m - minute
166// s - second
167// returns error code or ERR_OK
168//--------------------------------------------------
169int decodeUTCTime(ASN1_UTCTIME *tm,
170 int* y, int* M, int* d,
171 int* h, int* m, int* s);
172
173//==========================================================
174// converts ASN1 time to time_t
175//==========================================================
176int asn1time2time_t(ASN1_TIME* tm, time_t* pT);
177
178int asn1time2time_t_local(ASN1_TIME* tm, time_t* pT);
179
180//==========================================================
181// converts ASN1 time to string
182//==========================================================
183int asn1time2strYear(const SignedDoc* pSigDoc, ASN1_TIME* tm, char* buf, int year, int len);
184
185//==========================================================
186// converts ASN1 time to string
187//==========================================================
188int asn1time2str(const SignedDoc* pSigDoc, ASN1_TIME* tm, char* buf, int len);
189
190//===================================================================
191// converts time_t to timestamp string
192// t - time_t input value
193// szTimestamp - output buffer
194// len - length of buffer
195// returns error code or ERR_OK
196//===================================================================
197 EXP_OPTION int time_t2str(time_t t, char* szTimestamp, int len);
198
199//===================================================================
200// converts string to time_t
201// szTimestamp - input buffer
202// pT - address time_t output value
203// returns error code or ERR_OK
204//===================================================================
205EXP_OPTION int str2time_t(char* szTimestamp, time_t* pT);
206
207//--------------------------------------------------
208// Converts a filename according to platform rules
209// dest - destination buffer
210// destlen - destination buffer length
211// src - source filename
212// returns error code or ERR_OK
213//--------------------------------------------------
214EXP_OPTION int ddocConvertFileName(char* dest, int destlen, const char* src);
215
216//==========< only win32 fucntions >============
217
218#ifdef WIN32
219
220//--------------------------------------------------
221// Converts input OEM charset data to 16 bit unicode.
222// oem - 8 bit oem charset input data
223// unicode - address of pointer for allocated unicode string. Caller must free() !
224// outlen - address of length variable for unicode string
225// returns error code or ERR_OK
226//--------------------------------------------------
227EXP_OPTION int oem2unicode(const char* oem, char** unicode, int* outlen);
228
229//--------------------------------------------------
230// Converts input 16 bit unicode data to UTF8.
231// unicode - 16 bit unicode input data
232// utf8 - address of pointer for allocated utf8 string. Caller must free() !
233// outlen - address of length variable for utf8 string
234// returns error code or ERR_OK
235//--------------------------------------------------
236EXP_OPTION int unicode2utf8(const char* unicode, char** utf8, int* outlen);
237
238//--------------------------------------------------
239// Converts input OEM charset data to UTF-8
240// oem - 8 bit oem charset input data
241// utf8 - address of buffer allocated utf8 string.
242// len - size of buffer
243// returns error code or ERR_OK
244//--------------------------------------------------
245EXP_OPTION int oem2utf8(const char* oem, char* utf8, int len);
246
247//--------------------------------------------------
248// Converts input UTF-8 data to 16 bit unicode data.
249// utf8 - UTF-8 input data
250// unicode - address of pointer for allocated unicode string. Caller must free() !
251// outlen - address of length variable for unicode string
252// returns error code or ERR_OK
253//--------------------------------------------------
254EXP_OPTION int utf82unicode(const char* utf8, char** unicode, int* outlen);
255
256//--------------------------------------------------
257// Converts input 16 bit unicode data to oem charset data.
258// unicode - 16 bit unicode input data
259// oem - address of pointer for allocated oem string. Caller must free() !
260// outlen - address of length variable for oem string
261// returns error code or ERR_OK
262//--------------------------------------------------
263EXP_OPTION int unicode2oem(const char* unicode, char** oem, int* outlen);
264
265//--------------------------------------------------
266// Converts input UTF-8 data to OEM charset data
267// utf8 - UTF-8 input data
268// oem - address of buffer for oem string.
269// len - size of buffer
270// returns error code or ERR_OK
271//--------------------------------------------------
272EXP_OPTION int utf82oem(const char* utf8, char* oem, int len);
273
274//--------------------------------------------------
275// Converts input UTF-8 data to OEM charset data
276// pSigDoc - signed doc object
277// pDf - data file obejct
278// outFileName - output buffer
279// len - length of output buffer
280// returns error code or ERR_OK
281//--------------------------------------------------
282EXP_OPTION int getDataFileFileName(SignedDoc* pSigDoc, DataFile* pDf, char* outFileName, int len);
283
284#endif // WIN32
285
286//--------------------------------------------------
287// Releases mem-block allocated by lib. In win32
288// this must be done since the mem was allocated by dll
289// and must also be released by dll that allocated it.
290// p - mem to be freed
291//--------------------------------------------------
292EXP_OPTION void freeLibMem(void* p);
293
294
295#ifdef __cplusplus
296}
297#endif
298
299
300#endif // __DIGIDOC_CONVERT_H__
301
302
303
Definition DigiDocObj.h:122
Definition DigiDocMem.h:32
Definition DigiDocObj.h:177