Output is implemented via wxWidget's logging feature
This commit is contained in:
parent
8933dfc4ce
commit
1752084b24
@ -29,10 +29,8 @@ int _tmain(int argc, _TCHAR *argv[])
|
|||||||
|
|
||||||
// Initialize wxWidgets.
|
// Initialize wxWidgets.
|
||||||
wxInitializer initializer;
|
wxInitializer initializer;
|
||||||
if (!initializer.IsOk()) {
|
if (!initializer.IsOk())
|
||||||
_ftprintf(stderr, wxT("Failed to initialize the wxWidgets library, aborting.\n"));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
// Parse command line.
|
// Parse command line.
|
||||||
static const wxCmdLineEntryDesc cmdLineDesc[] =
|
static const wxCmdLineEntryDesc cmdLineDesc[] =
|
||||||
@ -61,10 +59,8 @@ int _tmain(int argc, _TCHAR *argv[])
|
|||||||
// Load input XML document.
|
// Load input XML document.
|
||||||
const wxString& filenameIn = parser.GetParam(0);
|
const wxString& filenameIn = parser.GetParam(0);
|
||||||
wxXmlDocument doc;
|
wxXmlDocument doc;
|
||||||
if (!doc.Load(filenameIn, "UTF-8", wxXMLDOC_KEEP_WHITESPACE_NODES)) {
|
if (!doc.Load(filenameIn, "UTF-8", wxXMLDOC_KEEP_WHITESPACE_NODES))
|
||||||
_ftprintf(stderr, wxT("%s: error USX0001: Error opening input file.\n"), filenameIn.fn_str());
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
// Examine prologue if the document is already signed and remove all signatures found.
|
// Examine prologue if the document is already signed and remove all signatures found.
|
||||||
wxXmlNode *document = doc.GetDocumentNode();
|
wxXmlNode *document = doc.GetDocumentNode();
|
||||||
@ -88,10 +84,8 @@ int _tmain(int argc, _TCHAR *argv[])
|
|||||||
|
|
||||||
// Create RSA AES cryptographic session.
|
// Create RSA AES cryptographic session.
|
||||||
wxCryptoSessionRSAAES cs;
|
wxCryptoSessionRSAAES cs;
|
||||||
if (!cs.IsOk()) {
|
if (!cs.IsOk())
|
||||||
_ftprintf(stderr, wxT("Failed to create cryptographics session.\n"));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
// Import the private key into the session from resources.
|
// Import the private key into the session from resources.
|
||||||
{
|
{
|
||||||
@ -101,25 +95,19 @@ int _tmain(int argc, _TCHAR *argv[])
|
|||||||
wxASSERT_MSG(res_handle, wxT("loading resource failed"));
|
wxASSERT_MSG(res_handle, wxT("loading resource failed"));
|
||||||
|
|
||||||
wxCryptoKey ck;
|
wxCryptoKey ck;
|
||||||
if (!ck.ImportPrivate(cs, ::LockResource(res_handle), ::SizeofResource(NULL, res))) {
|
if (!ck.ImportPrivate(cs, ::LockResource(res_handle), ::SizeofResource(NULL, res)))
|
||||||
_ftprintf(stderr, wxT("Failed to import private key.\n"));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Hash the XML content.
|
// Hash the XML content.
|
||||||
wxCryptoHashSHA1 ch(cs);
|
wxCryptoHashSHA1 ch(cs);
|
||||||
if (!wxXmlHashNode(ch, document)) {
|
if (!wxXmlHashNode(ch, document))
|
||||||
_ftprintf(stderr, wxT("%s: error USX0002: Error hashing input file.\n"), filenameIn.fn_str());
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
|
||||||
|
|
||||||
// Sign the hash.
|
// Sign the hash.
|
||||||
wxMemoryBuffer sig;
|
wxMemoryBuffer sig;
|
||||||
if (!ch.Sign(sig)) {
|
if (!ch.Sign(sig))
|
||||||
_ftprintf(stderr, wxT("%s: error USX0003: Error signing hash.\n"), filenameIn.fn_str());
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
|
||||||
|
|
||||||
// Encode signature (Base64) and append to the document prolog.
|
// Encode signature (Base64) and append to the document prolog.
|
||||||
wxString signature;
|
wxString signature;
|
||||||
@ -130,7 +118,7 @@ int _tmain(int argc, _TCHAR *argv[])
|
|||||||
// Write output XML document.
|
// Write output XML document.
|
||||||
const wxString& filenameOut = parser.GetParam(1);
|
const wxString& filenameOut = parser.GetParam(1);
|
||||||
if (!doc.Save(filenameOut, wxXML_NO_INDENTATION)) {
|
if (!doc.Save(filenameOut, wxXML_NO_INDENTATION)) {
|
||||||
_ftprintf(stderr, wxT("%s: error USX0004: Error writing output file.\n"), filenameOut.fn_str());
|
wxLogError(wxT("%s: error USX0004: Error writing output file.\n"), filenameOut.fn_str());
|
||||||
|
|
||||||
// Remove the output file (if exists).
|
// Remove the output file (if exists).
|
||||||
wxRemoveFile(filenameOut);
|
wxRemoveFile(filenameOut);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user