Estonian ID Card C-library
Loading...
Searching...
No Matches
DigiDocGen.h
1#ifndef __DIGIDOC_GEN_H__
2#define __DIGIDOC_GEN_H__
3//==================================================
4// FILE: DigiDocGen.h
5// PROJECT: Digi Doc
6// DESCRIPTION: DigiDoc helper routines for XML generation
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// 11.04.2006 Veiko Sinivee
22// Creation
23//==================================================
24
25#include <libdigidoc/DigiDocDefs.h>
26#include <libdigidoc/DigiDocObj.h>
27#include <libdigidoc/DigiDocMem.h>
28
29
30//==========< XML generation routines >========================
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36#ifdef WITH_TIMETSTAMP_STRUCT
37// contains timestamp data
38typedef struct Timestamp_st {
39 int year;
40 int mon;
41 int day;
42 int hour;
43 int min;
44 int sec;
45 int tz;
46} Timestamp;
47
48// converts timestamp string to it's components
49EXP_OPTION int convertStringToTimestamp(const SignedDoc* pSigDoc, const char* szTimestamp, Timestamp* pTimestamp);
50// converts timestamp to string
51EXP_OPTION int convertTimestampToString(const SignedDoc* pSigDoc, const Timestamp* pTimestamp, char* szTimestamp, int len);
52// creates new timestamp object
53EXP_OPTION int Timestamp_new(Timestamp **, int year,int month,int day,int hour,int minute,int second,int timezone);
54// frees this timestamp object
55EXP_OPTION void Timestamp_free(Timestamp* pTimestamp);
56
57#endif
58
59//============================================================
60// Creates a timestamp string
61// buf - output buffer
62// len - length of output buffer
63// returns number of output bytes written
64//============================================================
65int createTimestamp(const SignedDoc* pSigDoc, char* buf, int len);
66
67// converts timestamp string to time_t value
68EXP_OPTION time_t convertStringToTimeT(const SignedDoc* pSigDoc, const char* szTimestamp);
69
70
71//--------------------------------------------------
72// Appends an xml element start to buffer, but no ">"
73// pBuf - memory buffer to store xml [REQUIRED]
74// elemName - xml element name [REQUIRED]
75// returns error code or ERR_OK
76//--------------------------------------------------
77int ddocGen_startElemBegin(DigiDocMemBuf* pBuf, const char* elemName);
78
79//--------------------------------------------------
80// Appends an xml element start tag end to buffer - ">"
81// pBuf - memory buffer to store xml [REQUIRED]
82// returns error code or ERR_OK
83//--------------------------------------------------
84int ddocGen_startElemEnd(DigiDocMemBuf* pBuf);
85
86//--------------------------------------------------
87// Appends an xml element start to buffer - <tag>
88// pBuf - memory buffer to store xml [REQUIRED]
89// elemName - xml element name [REQUIRED]
90// returns error code or ERR_OK
91//--------------------------------------------------
92int ddocGen_startElem(DigiDocMemBuf* pBuf, const char* elemName);
93
94//--------------------------------------------------
95// Appends an xml element end to buffer
96// pBuf - memory buffer to store xml [REQUIRED]
97// elemName - xml element name [REQUIRED]
98// returns error code or ERR_OK
99//--------------------------------------------------
100int ddocGen_endElem(DigiDocMemBuf* pBuf, const char* elemName);
101
102//--------------------------------------------------
103// Appends an xml element's atribute to buffer
104// pBuf - memory buffer to store xml [REQUIRED]
105// name - xml atribute name [REQUIRED]
106// value - xml atribute value [REQUIRED]
107// returns error code or ERR_OK
108//--------------------------------------------------
109int ddocGen_addAtribute(DigiDocMemBuf* pBuf, const char* name, const char* value);
110
111
112//--------------------------------------------------
113// Helper function that escapes XML special chars
114// src - input data
115// srclen - length of input data. Use -1 for 0 terminated strings
116// dest - address of output buffer. Caller is responsible for deallocating it!
117// returns error code or ERR_OK
118//--------------------------------------------------
119int escapeXMLSymbols(const char* src, int srclen, char** dest);
120
121//--------------------------------------------------
122// Helper function that escapes XML special chars in xml element body
123// src - input data
124// srclen - length of input data. Use -1 for 0 terminated strings
125// dest - address of output buffer. Caller is responsible for deallocating it!
126// returns error code or ERR_OK
127//--------------------------------------------------
128int escapeTextNode(const char* src, int srclen, char** dest);
129
130
131//================< functions generating DigiDoc formats 1.0 - 1.3 > =================================
132
133// writes the signed doc to a file
134EXP_OPTION int createSignedDoc(SignedDoc* pSigDoc, const char* szOldFile, const char* szSigDocFile);
135
136//============================================================
137// Canonicalizes XML
138// source - input data
139// len - input length
140// returns a newly allocated buffer with canonicalized XML
141// Caller must free() the result.
142//============================================================
143char* canonicalizeXML(char* source, int len);
144
145char* canonicalizeXMLBlock(char* source, int len, char* block, char* prefix);
146
147//============================================================
148// Creates a <SignedProperties> XML block
149// pSigDoc - signed document pointer
150// pSigInfo - signature info data
151// bWithEscapes - 1=escape xml sümbols, 0=don't escape
152// returns new <SignedProperties> node
153//============================================================
154char* createXMLSignedProperties(const SignedDoc* pSigDoc, const SignatureInfo* pSigInfo, int bWithEscapes);
155
156//============================================================
157// Generates DataFile elements XML form and stores it in a file
158// pSigDoc - signed document
159// pDataFile - data file object to be converted
160// szDataFile - input file name
161// hFile - output file handle
162// pMBufXML - output buffer if we want data to be returned in mem buf
163//============================================================
164EXP_OPTION int generateDataFileXML(SignedDoc* pSigDoc, DataFile* pDataFile,
165 const char* szDataFile, FILE* hFile, DigiDocMemBuf* pMBufXML);
166
167//--------------------------------------------------
168// Creates a new signed document in memory buffer
169// pSigDoc - signed doc info
170// szOldFile - name of old file on disk to copy DataFile contents
171// pMBuf - buffer for new digidoc document
172// returns error code or ERR_OK for success
173//--------------------------------------------------
174EXP_OPTION int createSignedDocInMemory(SignedDoc* pSigDoc, const char* szOldFile, DigiDocMemBuf* pMBuf);
175
176//--------------------------------------------------
177// Removes incomplete or orphoned signatures.
178// Signature is incomplete if it hasn't got the signature
179// value
180// pSigDoc - signed doc info
181// returns error code or ERR_OK for success
182//--------------------------------------------------
183EXP_OPTION int removeIncompleteSignatures(SignedDoc* pSigDoc);
184
185//--------------------------------------------------
186// Checks for incomplete or orphoned signatures.
187// Signature is incomplete if it hasn't got the signature
188// value
189// pSigDoc - signed doc info
190// returns error code if DigiDoc has orphoned signature or ERR_OK for success
191//--------------------------------------------------
192EXP_OPTION int hasIncompleteSignatures(SignedDoc* pSigDoc);
193
194
195#ifdef __cplusplus
196}
197#endif
198
199
200#endif // __DIGIDOC_GEN_H__
Definition DigiDocObj.h:122
Definition DigiDocMem.h:32
Definition DigiDocObj.h:154
Definition DigiDocObj.h:177