On Tue, 2015-04-14 at 18:28 +0200, Andreas Brzesowsky wrote:
> So please check my changes and add them to the repository.
Hi,
I tried your change on top of revision 1670 and the attached
encrypt.cpp test and it fails on AES encryptions, while without the
patch the test succeeds.
Could you have a look, please?
Bye,
zyx
--
http://www.litePDF.cz i...@litepdf.cz
#include <stdio.h>
#include "podofo.h"
using namespace PoDoFo;
static void drawPage(PdfMemDocument *memDocument)
{
PODOFO_RAISE_LOGIC_IF (!memDocument, "!memDocument");
PdfFont *pFont;
PdfPage *pPage;
PdfPainter painter;
pPage = memDocument->CreatePage(PdfPage::CreateStandardPageSize(ePdfPageSize_A4));
PODOFO_RAISE_LOGIC_IF (!pPage, "!pPage");
painter.SetPage(pPage);
pFont = memDocument->CreateFont("Helvetica");
PODOFO_RAISE_LOGIC_IF (!pFont, "!pFont");
pFont->SetFontSize(18.0);
painter.SetFont(pFont);
painter.DrawText(56.69, pPage->GetPageSize().GetHeight() - 56.69, "Hello World! Encrypted");
painter.FinishPage();
}
static void testEnctyption(PdfEncrypt::EPdfEncryptAlgorithm algo, PdfEncrypt::EPdfKeyLength keyLength, const char *pFileName)
{
PdfEncrypt *encrypt;
if (pFileName)
printf("Testing %s:\n", pFileName);
encrypt = PdfEncrypt::CreatePdfEncrypt("user", "owner", 0, algo, keyLength);
PODOFO_RAISE_LOGIC_IF (!encrypt, "!encrypt");
PdfMemDocument *memDocument = new PdfMemDocument();
PODOFO_RAISE_LOGIC_IF (!memDocument, "!memDocument");
memDocument->SetEncrypted(*encrypt);
delete encrypt;
PdfInfo *info = memDocument->GetInfo();
PODOFO_RAISE_LOGIC_IF (!info, "!info");
info->SetProducer("test");
drawPage(memDocument);
PdfRefCountedBuffer *buffer = new PdfRefCountedBuffer();
PODOFO_RAISE_LOGIC_IF (!buffer, "!buffer");
PdfOutputDevice outputDevice(buffer);
memDocument->Write(&outputDevice);
delete memDocument;
if (pFileName) {
FILE *f = fopen(pFileName, "wb");
PODOFO_RAISE_LOGIC_IF (!f, "!f");
fwrite(buffer->GetBuffer(), buffer->GetSize(), 1, f);
fclose(f);
}
memDocument = new PdfMemDocument();
PODOFO_RAISE_LOGIC_IF (!memDocument, "!memDocument (2)");
PdfRefCountedInputDevice inputDevice(buffer->GetBuffer(), buffer->GetSize());
try {
memDocument->Load(inputDevice);
} catch (const PdfError &error) {
if (error.GetError() == ePdfError_InvalidPassword) {
memDocument->SetPassword("user");
} else {
throw;
}
}
info = memDocument->GetInfo();
PODOFO_RAISE_LOGIC_IF (!info, "!info");
if (info->GetProducer().GetStringUtf8() != "test") {
fprintf(stderr, " Producer not set as expected 'test', but '%s' instead\n", info->GetProducer().GetString());
} else {
printf(" OK\n");
}
delete memDocument;
delete buffer;
}
int main(void)
{
PdfError::EnableLogging(false);
try {
testEnctyption(PdfEncrypt::ePdfEncryptAlgorithm_RC4V1, PdfEncrypt::ePdfKeyLength_40, "rc4v1.pdf");
testEnctyption(PdfEncrypt::ePdfEncryptAlgorithm_RC4V2, PdfEncrypt::ePdfKeyLength_128, "rc4v2.pdf");
testEnctyption(PdfEncrypt::ePdfEncryptAlgorithm_AESV2, PdfEncrypt::ePdfKeyLength_128, "aesv2.pdf");
testEnctyption(PdfEncrypt::ePdfEncryptAlgorithm_AESV3, PdfEncrypt::ePdfKeyLength_256, "aesv3.pdf");
} catch (const PdfError &error) {
fprintf (stderr, "Failed with error:\n");
error.PrintErrorMsg();
}
return 0;
}
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users