OutputAESEncodeStream::OutputAESEncodeStream(IByteWriterWithPosition* inTargetStream, const ByteList& inEncryptionKey, bool inOwnsStream) { mTargetStream = inTargetStream; mOwnsStream = inOwnsStream; if (!mTargetStream) return; mInIndex = mIn; // convert inEncryptionKey to internal rep and init encrypt [let's hope its 16...] mEncryptionKey = new unsigned char[inEncryptionKey.size()]; mEncryptionKeyLength = inEncryptionKey.size(); ByteList::const_iterator it = inEncryptionKey.begin(); size_t i = 0; for (; it != inEncryptionKey.end(); ++i, ++it) mEncryptionKey[i] = *it; mEncrypt.key(mEncryptionKey, mEncryptionKeyLength); // create IV and write it to output file [use existing PDFDate] MD5Generator md5; // encode current time PDFDate currentTime; currentTime.SetToCurrentTime(); md5.Accumulate(currentTime.ToString()); memcpy(mIV, (const unsigned char*)md5.ToStringAsString().c_str(),AES_BLOCK_SIZE); // md5 should give us the desired 16 bytes // now write mIV to the output stream mTargetStream->Write(mIV, AES_BLOCK_SIZE); }
EStatusCode PDFDateTest::Run() { EStatusCode status = PDFHummus::eSuccess; // Empty Date PDFDate emptyDate; if(emptyDate.ToString() != "") { status = PDFHummus::eFailure; cout<<"wrong string conversion for empty date - "<<emptyDate.ToString().c_str()<<"\n"; } // Year only Date PDFDate yearDate; yearDate.Year = 1984; if(yearDate.ToString() != "D:1984") { status = PDFHummus::eFailure; cout<<"wrong string conversion for year date - "<<yearDate.ToString().c_str()<<"\n"; } // Day only Date PDFDate dayDate; dayDate.Year = 1984; dayDate.Month = 4; dayDate.Day = 3; if(dayDate.ToString() != "D:19840403") { status = PDFHummus::eFailure; cout<<"wrong string conversion for day date - "<<dayDate.ToString().c_str()<<"\n"; } // local Time Date PDFDate localTimeDate; localTimeDate.Year = 1984; localTimeDate.Month = 4; localTimeDate.Day = 3; localTimeDate.Hour = 18; localTimeDate.Minute = 30; localTimeDate.Second = 45; if(localTimeDate.ToString() != "D:19840403183045") { status = PDFHummus::eFailure; cout<<"wrong string conversion for local date - "<<localTimeDate.ToString().c_str()<<"\n"; } // Fully qualified Time date PDFDate fullDate; fullDate.Year = 1984; fullDate.Month = 4; fullDate.Day = 3; fullDate.Hour = 18; fullDate.Minute = 30; fullDate.Second = 45; fullDate.UTC = PDFDate::eEarlier; fullDate.HourFromUTC = 2; fullDate.MinuteFromUTC = 0; if(fullDate.ToString() != "D:19840403183045-02'00'") { status = PDFHummus::eFailure; cout<<"wrong string conversion for full date - "<<fullDate.ToString().c_str()<<"\n"; } // Just display the current time as set by PDFDate PDFDate currentDate; currentDate.SetToCurrentTime(); cout<<"Current time as represented in PDFDate - "<<currentDate.ToString().c_str()<<"\n"; return status; }