33
33
34
34
#include < xercesc/util/OutOfMemoryException.hpp>
35
35
36
- #include < fstream>
37
36
#include < set>
38
37
39
38
using namespace digidoc ;
@@ -110,16 +109,18 @@ void ASiC_E::save(const string &path)
110
109
s.addFile (" META-INF/manifest.xml" , manifest, zproperty (" META-INF/manifest.xml" ));
111
110
112
111
for (const DataFile *file: dataFiles ())
113
- s.addFile (file->fileName (), *(static_cast <const DataFilePrivate*>(file)->m_is . get () ), zproperty (file->fileName ()));
112
+ s.addFile (file->fileName (), *(static_cast <const DataFilePrivate*>(file)->m_is ), zproperty (file->fileName ()));
114
113
114
+ std::set<Signatures*> saved;
115
115
unsigned int i = 0 ;
116
116
for (Signature *iter: signatures ())
117
117
{
118
118
string file = Log::format (" META-INF/signatures%u.xml" , i++);
119
- SignatureXAdES_B *signature = static_cast <SignatureXAdES_B*>(iter);
120
-
119
+ auto *signature = static_cast <SignatureXAdES_B*>(iter);
120
+ if (!saved.insert (signature->signatures .get ()).second )
121
+ continue ;
121
122
stringstream ofs;
122
- signature->saveToXml (ofs);
123
+ signature->signatures -> save (ofs);
123
124
s.addFile (file, ofs, zproperty (file));
124
125
}
125
126
}
@@ -138,7 +139,7 @@ unique_ptr<Container> ASiC_E::createInternal(const string &path)
138
139
* @param sigdata signature, which is added to the container.
139
140
* @throws Exception throws exception if there are no documents in container.
140
141
*/
141
- void ASiC_E::addAdESSignature (istream &sigdata )
142
+ void ASiC_E::addAdESSignature (istream &data )
142
143
{
143
144
if (dataFiles ().empty ())
144
145
THROW (" No documents in container, can not add signature." );
@@ -147,7 +148,9 @@ void ASiC_E::addAdESSignature(istream &sigdata)
147
148
148
149
try
149
150
{
150
- addSignature (make_unique<SignatureXAdES_LTA>(sigdata, this ));
151
+ auto signatures = make_shared<Signatures>(data, this );
152
+ for (size_t i = 0 , count = signatures->count (); i < count; ++i)
153
+ addSignature (make_unique<SignatureXAdES_LTA>(signatures, i, this ));
151
154
}
152
155
catch (const Exception &e)
153
156
{
@@ -218,7 +221,7 @@ void ASiC_E::parseManifestAndLoadFiles(const ZipSerialize &z)
218
221
DEBUG (" ASiC_E::readManifest()" );
219
222
220
223
const vector<string> &list = z.list ();
221
- size_t mcount = size_t (count (list.cbegin (), list.cend (), " META-INF/manifest.xml" ));
224
+ auto mcount = size_t (count (list.cbegin (), list.cend (), " META-INF/manifest.xml" ));
222
225
if (mcount < 1 )
223
226
THROW (" Manifest file is missing" );
224
227
if (mcount > 1 )
@@ -254,7 +257,7 @@ void ASiC_E::parseManifestAndLoadFiles(const ZipSerialize &z)
254
257
if (file.full_path ().back () == ' /' ) // Skip Directory entries
255
258
continue ;
256
259
257
- size_t fcount = size_t (count (list.cbegin (), list.cend (), file.full_path ()));
260
+ auto fcount = size_t (count (list.cbegin (), list.cend (), file.full_path ()));
258
261
if (fcount < 1 )
259
262
THROW (" File described in manifest '%s' does not exist in container." , file.full_path ().c_str ());
260
263
if (fcount > 1 )
@@ -287,7 +290,9 @@ void ASiC_E::parseManifestAndLoadFiles(const ZipSerialize &z)
287
290
{
288
291
stringstream data;
289
292
z.extract (file, data);
290
- addSignature (make_unique<SignatureXAdES_LTA>(data, this , true ));
293
+ auto signatures = make_shared<Signatures>(data, this );
294
+ for (size_t i = 0 , count = signatures->count (); i < count; ++i)
295
+ addSignature (make_unique<SignatureXAdES_LTA>(signatures, i, this ));
291
296
}
292
297
catch (const Exception &e)
293
298
{
@@ -354,7 +359,7 @@ Signature* ASiC_E::prepareSignature(Signer *signer)
354
359
355
360
Signature *ASiC_E::sign (Signer* signer)
356
361
{
357
- SignatureXAdES_LTA *s = static_cast <SignatureXAdES_LTA*>(prepareSignature (signer));
362
+ auto *s = static_cast <SignatureXAdES_LTA*>(prepareSignature (signer));
358
363
try
359
364
{
360
365
s->setSignatureValue (signer->sign (s->signatureMethod (), s->dataToSign ()));
0 commit comments