Example #1
0
void PdfFont::WriteStringToStream( const PdfString & rsString, PdfStream* pStream )
{
    if( !m_pEncoding )
    {
	PODOFO_RAISE_ERROR( ePdfError_InvalidHandle );
    }

    PdfString sEncoded = m_pEncoding->ConvertToEncoding( rsString, this );
    if( sEncoded.IsUnicode() ) 
    {
        PODOFO_RAISE_ERROR_INFO( ePdfError_InternalLogic, "ConvertToEncoding must not return a unicode string" );
    }

    pdf_long  lLen    = 0;
    char* pBuffer = NULL;

    std::auto_ptr<PdfFilter> pFilter = PdfFilterFactory::Create( ePdfFilter_ASCIIHexDecode );    
    pFilter->Encode( sEncoded.GetString(), sEncoded.GetLength(), &pBuffer, &lLen );

    pStream->Append( "<", 1 );
    pStream->Append( pBuffer, lLen );
    pStream->Append( ">", 1 );

    free( pBuffer );
}
void EncryptTest::TestAuthenticate( PdfEncrypt* pEncrypt, int keyLength, int rValue ) 
{
    PdfString documentId;
    documentId.SetHexData( "BF37541A9083A51619AD5924ECF156DF", 32 );

    pEncrypt->GenerateEncryptionKey( documentId );

    std::string documentIdStr( documentId.GetString(), documentId.GetLength() );
    std::string password = "******";
    std::string uValue( reinterpret_cast<const char*>(pEncrypt->GetUValue()), 32 );
    std::string oValue( reinterpret_cast<const char*>(pEncrypt->GetOValue()), 32 );

    // Authenticate using user password
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "authenticate using user password",
                                  pEncrypt->Authenticate( documentIdStr, std::string("user"),
                                                          uValue, oValue, pEncrypt->GetPValue(), keyLength, rValue ),
                                  true );

    // Authenticate using owner password
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "authenticate using owner password",
                                  pEncrypt->Authenticate( documentIdStr, std::string("podofo"), 
                                                          uValue, oValue, pEncrypt->GetPValue(), keyLength, rValue ),
                                  true );
}