@@ -35,16 +35,19 @@ using namespace digidoc;
35
35
using namespace digidoc ::util;
36
36
using namespace std ;
37
37
38
- const string_view ASiC_E::ASIC_TM_PROFILE = " time-mark" ;
39
- const string_view ASiC_E::ASIC_TS_PROFILE = " time-stamp" ;
40
- const string_view ASiC_E::ASIC_TSA_PROFILE = " time-stamp-archive" ;
41
- const string_view ASiC_E::ASIC_TMA_PROFILE = " time-mark-archive" ;
42
38
constexpr string_view MANIFEST_NS {" urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" };
43
39
44
40
class ASiC_E ::Private
45
41
{
46
42
public:
43
+ string unique_name () const
44
+ {
45
+ string file;
46
+ for (unsigned int i = 0 ; signatures.count (file = Log::format (" META-INF/signatures%u.xml" , i++)); );
47
+ return file;
48
+ }
47
49
vector<DataFile*> metadata;
50
+ map<string,Signatures*> signatures;
48
51
};
49
52
50
53
/* *
@@ -57,7 +60,7 @@ ASiC_E::ASiC_E()
57
60
}
58
61
59
62
/* *
60
- * Opens BDOC container from a file
63
+ * Opens ASiC container from a file
61
64
*/
62
65
ASiC_E::ASiC_E (const string &path)
63
66
: ASiContainer(MIMETYPE_ASIC_E)
@@ -101,24 +104,28 @@ void ASiC_E::save(const string &path)
101
104
s.addFile (" mimetype" , mimetype, zproperty (" mimetype" ), false );
102
105
103
106
stringstream manifest;
104
- createManifest (manifest);
107
+ if (!createManifest ().save (manifest))
108
+ THROW (" Failed to create manifest XML" );
105
109
s.addFile (" META-INF/manifest.xml" , manifest, zproperty (" META-INF/manifest.xml" ));
106
110
107
111
for (const DataFile *file: dataFiles ())
108
112
s.addFile (file->fileName (), *(static_cast <const DataFilePrivate*>(file)->m_is ), zproperty (file->fileName ()));
109
113
110
114
std::set<Signatures*> saved;
111
- unsigned int i = 0 ;
112
115
for (Signature *iter: signatures ())
113
116
{
114
- string file = Log::format (" META-INF/signatures%u.xml" , i++);
115
- auto *signature = static_cast <SignatureXAdES_B*>(iter);
116
- if (!saved.insert (signature->signatures .get ()).second )
117
+ auto *signatures = static_cast <SignatureXAdES_B*>(iter)->signatures .get ();
118
+ if (!saved.insert (signatures).second )
117
119
continue ;
120
+ auto name = find_if (d->signatures .cbegin (), d->signatures .cend (), [signatures](const auto &k){
121
+ return k.second == signatures;
122
+ });
123
+ if (name == d->signatures .cend ())
124
+ THROW (" Unkown signature object" );
118
125
stringstream ofs;
119
- if (!signature-> signatures ->save (ofs))
126
+ if (!signatures->save (ofs))
120
127
THROW (" Failed to create signature XML file." );
121
- s.addFile (file , ofs, zproperty (file ));
128
+ s.addFile (name-> first , ofs, zproperty (name-> first ));
122
129
}
123
130
}
124
131
@@ -142,12 +149,9 @@ void ASiC_E::addAdESSignature(istream &data)
142
149
THROW (" No documents in container, can not add signature." );
143
150
if (mediaType () != MIMETYPE_ASIC_E)
144
151
THROW (" '%s' format is not supported" , mediaType ().c_str ());
145
-
146
152
try
147
153
{
148
- auto signatures = make_shared<Signatures>(data, this );
149
- for (auto s = signatures->signature (); s; s++)
150
- addSignature (make_unique<SignatureXAdES_LTA>(signatures, s, this ));
154
+ loadSignatures (data, d->unique_name ());
151
155
}
152
156
catch (const Exception &e)
153
157
{
@@ -164,14 +168,10 @@ unique_ptr<Container> ASiC_E::openInternal(const string &path)
164
168
/* *
165
169
* Creates BDoc container manifest file and returns its path.
166
170
*
167
- * Note: If non-ascii characters are present in XML data, we depend on the LANG variable to be set properly
168
- * (see iconv --list for the list of supported encoding values for libiconv).
169
- *
170
- *
171
171
* @return returns created manifest file path.
172
172
* @throws Exception exception is thrown if manifest file creation failed.
173
173
*/
174
- void ASiC_E::createManifest (ostream &os)
174
+ XMLDocument ASiC_E::createManifest () const
175
175
{
176
176
DEBUG (" ASiC_E::createManifest()" );
177
177
auto doc = XMLDocument::create (" manifest" , MANIFEST_NS, " manifest" );
@@ -184,8 +184,15 @@ void ASiC_E::createManifest(ostream &os)
184
184
add (" /" , mediaType ());
185
185
for (const DataFile *file: dataFiles ())
186
186
add (file->fileName (), file->mediaType ());
187
- if (!doc.save (os))
188
- THROW (" Failed to create manifest XML" );
187
+ return doc;
188
+ }
189
+
190
+ void ASiC_E::loadSignatures (istream &data, const string &file)
191
+ {
192
+ auto signatures = make_shared<Signatures>(data, mediaType ());
193
+ d->signatures .emplace (file, signatures.get ());
194
+ for (auto s = signatures->signature (); s; s++)
195
+ addSignature (make_unique<SignatureXAdES_LTA>(signatures, s, this ));
189
196
}
190
197
191
198
/* *
@@ -251,9 +258,7 @@ void ASiC_E::parseManifestAndLoadFiles(const ZipSerialize &z)
251
258
try
252
259
{
253
260
auto data = z.extract <stringstream>(file);
254
- auto signatures = make_shared<Signatures>(data, this );
255
- for (auto s = signatures->signature (); s; s++)
256
- addSignature (make_unique<SignatureXAdES_LTA>(signatures, s, this ));
261
+ loadSignatures (data, file);
257
262
}
258
263
catch (const Exception &e)
259
264
{
@@ -286,7 +291,9 @@ Signature* ASiC_E::prepareSignature(Signer *signer)
286
291
THROW (" No documents in container, can not sign container." );
287
292
if (!signer)
288
293
THROW (" Null pointer in ASiC_E::sign" );
289
- return addSignature (make_unique<SignatureXAdES_LTA>(newSignatureId (), this , signer));
294
+ auto signatures = make_shared<Signatures>();
295
+ d->signatures .emplace (d->unique_name (), signatures.get ());
296
+ return addSignature (make_unique<SignatureXAdES_LTA>(signatures, newSignatureId (), this , signer));
290
297
}
291
298
292
299
Signature *ASiC_E::sign (Signer* signer)
0 commit comments