/**
@SYMTestCaseID          SYSLIB-STORE-CT-1127
@SYMTestCaseDesc	    Stream encryption test.
                        Tests the functionality of REncryptStream and RDecryptStream classes
@SYMTestPriority 	    High
@SYMTestActions  	    Tests for writing an encrypted string to a stream,reading back the data,decrypt and
                        check with the original data.
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void testSimpleStreamEncryptionL()
    {
	test.Next(_L(" @SYMTestCaseID:SYSLIB-STORE-CT-1127 "));
   	CPBEncryptElement* elementKey = CPBEncryptElement::NewL(KTestPassword);
	CleanupStack::PushL(elementKey);
	TParsePtrC parse(KFileLocationSpec);
	
	RFileWriteStream writeStream;
    writeStream.PushL();
    User::LeaveIfError(writeStream.Replace(TheFs, parse.NameAndExt(), EFileWrite));

	REncryptStream encryptStream;
	encryptStream.OpenLC(writeStream, *elementKey);

    encryptStream << KTestDes;
    encryptStream.CommitL();
    writeStream.CommitL();
    CleanupStack::PopAndDestroy(2); // encryptStream, writeStream

    RFileReadStream readStream;
    readStream.PushL();
    User::LeaveIfError(readStream.Open(TheFs, parse.NameAndExt(), EFileWrite));

    RDecryptStream decryptStream;
	decryptStream.OpenLC(readStream, *elementKey);

    decryptStream >> TheBuf;

    test(KTestDes == TheBuf);

    CleanupStack::PopAndDestroy(3, elementKey); // decryptStream, readStream
    }
Exemple #2
0
//存档
void TPlayerInfo::WriterPlayerInfo()
{
    RFs oFs;
    if (oFs.Connect())
    {
        return;
    };
    RFileWriteStream oWriteStream;
    if (oWriteStream.Replace(oFs, *iFileName, EFileWrite))
    {
        oFs.Close();
        return;
    };
    oWriteStream.PushL();
    TInt32 playerCount = AWARD_PLAYER_COUNT;
    oWriteStream << playerCount;
    for (TInt i = 0; i < playerCount; i++)
    {
        if (i < AWARD_PLAYER_COUNT)
        {
            //iPlayerArray[i].ExternalizeL(oWriteStream);
            iPlayerList[i]->ExternalizeL(oWriteStream);
        }
    }
    oWriteStream.CommitL();
    oWriteStream.Pop();
    oWriteStream.Release();
    oFs.Close();
}
void CJavaDebugAgentSettings::SaveL(const TDesC& aPrefsFile) const
{
    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);

    RFileWriteStream out;
    out.PushL();
    TInt err = out.Create(fs, aPrefsFile, EFileWrite);
    if (err != KErrNone) {
        // Try to eliminate the problem if we can
        switch (err) {
        case KErrAlreadyExists:
            fs.Delete(aPrefsFile);
            break;
        case KErrPathNotFound:
            fs.MkDirAll(aPrefsFile);
            break;
        default:
            User::Leave(err);
            break;
        }
        User::LeaveIfError(out.Create(fs, aPrefsFile, EFileWrite));
    }

    SaveL(&out);
    out.Close();
    out.Pop();
    CleanupStack::PopAndDestroy(&fs);
}
// -----------------------------------------------------------------------------
// CSisxUIStartupFile::WritePrivateStartupItemsL
// Write startup items into private file.
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
void CSisxUIStartupFile::WritePrivateStartupItemsL( RArray<TStartupTaskParam>& aStartupItems )
    {
    if ( PrivateFileExists() )
        {
        iFileSession.Delete( *iPrivateFile );
        }

    if ( aStartupItems.Count() > 0 )
        {
        RFileWriteStream writer;
        writer.PushL();    
        User::LeaveIfError( writer.Create( iFileSession, *iPrivateFile, EFileWrite ) );
    
        // Write the number of entries to the file
        writer.WriteInt32L( aStartupItems.Count() );
        
        // Write file names to the file
        for ( TInt index = 0; index < aStartupItems.Count(); index++ )
            {
            if ( iFileSession.IsValidName( aStartupItems[index].iFileName ) )
                {            
                writer << aStartupItems[index].iFileName;
                }
            else
                {
                User::Leave( KErrArgument );            
                }               
            }

        writer.CommitL();    
        CleanupStack::PopAndDestroy(); // writer
        }    
    }
// -----------------------------------------------------------------------------
// CDRMHelperServer::StoreL().
// This function store internal list into data file
// -----------------------------------------------------------------------------
//
void CDRMHelperServer::StoreL()
    {

#ifdef _DRM_TESTING
    WriteL(_L8("StoreL"));
#endif

    RFileWriteStream file;
    User::LeaveIfError(file.Replace( iFs , DataFileL(iFs).FullName() , EFileWrite ));
    file.PushL();
    ExternalizeL(file);
    file.CommitL();
    CleanupStack::PopAndDestroy(&file);//file
    }
void CMtfTestActionSaveMsvIdParamToFile::ExecuteActionL()
	{
	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionSaveMsvIdParamToFile);
		
	TMsvId messageId = ObtainValueParameterL<TMsvId>( TestCase(), ActionParameters().Parameter(0) );										
	HBufC* paramFilePath = ObtainParameterReferenceL<HBufC>(TestCase(),ActionParameters().Parameter(1));
 
 	
 	RFs fs;
 	User::LeaveIfError( fs.Connect() );
 	CleanupClosePushL( fs );
 	
	TInt err = fs.MkDir( *paramFilePath ); 
	
	if ( ! ( (err == KErrNone ) || ( err == KErrAlreadyExists ) ) )
	{	
		User::LeaveIfError( err );
	}
	// else dir created successfully or already created.
	
	RFileWriteStream rf;
	err = rf.Open( fs , *paramFilePath , EFileWrite );
	if ( err == KErrNotFound )
	{
		err = rf.Create( fs, *paramFilePath , EFileWrite );
	}	
	User::LeaveIfError(err);
	
	rf.PushL();
		// Writes may leave.
		
	rf << messageId; 

	rf.CommitL();
	rf.Pop();
	rf.Release();
			
 	CleanupStack::PopAndDestroy(); // fs

	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionSaveMsvIdParamToFile);
	TestCase().ActionCompletedL(*this);	
	
	
	}
//////////////////////////////////////////////////////////////////////////////////
//	Test fix for INC023303: CX509Certificate externalize - internalize don't work 
//////////////////////////////////////////////////////////////////////////////////
void CSyntaxTest::TestInternalizeExternalizeL(CX509Certificate* aCert)
	{
	RFileWriteStream newwriter;
	newwriter.PushL();
	User::LeaveIfError(newwriter.Replace(iFs,_L("x509stream"),EFileStream));
	
	aCert->ExternalizeL(newwriter);
	newwriter.CommitL();
	CleanupStack::PopAndDestroy(1);//newwriter
	
	RFileReadStream newreader;
	newreader.PushL();
	newreader.Open(iFs,_L("x509stream"),EFileStream);
	CX509Certificate* readCert=CX509Certificate::NewLC(newreader); //Use the stream to create new cert

	if (!readCert->IsEqualL(*aCert))
		User::Leave(KErrGeneral);

//	iFs.Delete(_L("x509stream"));
	CleanupStack::PopAndDestroy(2);	//	readCert, newreader
	}
/**
@SYMTestCaseID          PDS-STORE-CT-4042
@SYMTestCaseDesc	    Tests for attaching write stream and read stream to an encrypted stream.
@SYMTestPriority 	    High
@SYMTestActions  	    Encrypt data and write to a store.Read the encrypted data for decrypting and compare the result.
@SYMTestExpectedResults Test must not fail
@SYMDEF                 DEF135804
*/
LOCAL_C void testEncryptionDataAttachL()
	{
	test.Next(_L(" @SYMTestCaseID:PDS-STORE-CT-4042 "));
	CPBEncryptElement* elementKey = CPBEncryptElement::NewLC(KTestPassword);
	TParsePtrC parse(KFileLocationSpec);
	
	RFileWriteStream writeStream;
	writeStream.PushL();
	User::LeaveIfError(writeStream.Replace(TheFs, parse.NameAndExt(), EFileWrite));
	
	REncryptStream encryptStream;
	TRAPD(ret, encryptStream.AttachL(writeStream, *elementKey));
	test(ret == KErrNone);
	encryptStream.PushL();
	
	encryptStream << KTestDes;
	encryptStream.CommitL();
	writeStream.CommitL();
	
	CleanupStack::PopAndDestroy(2); // encryptStream, writeStream
	
	const CPBEncryptionData& encryptData = elementKey->EncryptionData();
	
	CPBEncryptElement* newElementKey = CPBEncryptElement::NewLC(encryptData, KTestPassword);
	
	RFileReadStream readStream;
	readStream.PushL();
	User::LeaveIfError(readStream.Open(TheFs, parse.NameAndExt(), EFileWrite));
	
	
	RDecryptStream decryptStream;
	decryptStream.AttachL(readStream, *newElementKey);
	decryptStream.PushL();
	
	decryptStream >> TheBuf;
	
	test(KTestDes == TheBuf);
	
	CleanupStack::PopAndDestroy(4, elementKey);
	}
// ---------------------------------------------------------------------------
// 
// ---------------------------------------------------------------------------
//
void CAiwPrintingProvider::DoHandleCmdL(TInt aMenuCmdId,
                            const CAiwGenericParamList& aInParamList,
                            CAiwGenericParamList& aOutParamList,
                            TUint /*aCmdOptions*/,
                            const MAiwNotifyCallback* aCallback)
    {
    if ( aMenuCmdId == KAiwCmdPrint || aMenuCmdId == KAiwCmdPrintPreview  )
        {
        FLOG(_L("[CAiwPrintingProvider]<<<  DoHandleCmdL"));
        
        CAiwGenericParamList* checkedParams = CAiwGenericParamList::NewL();
        
        iConsumerInParamList = &aInParamList;
        iConsumerOutParamList = &aOutParamList;
        iConsumerCallback = aCallback;
        
        TInt index( 0 );
	    const TAiwGenericParam* param = aInParamList.FindFirst(index,
	            EGenericParamFile,
	            EVariantTypeDesC);
	    while ( index != KErrNotFound )
			{
	        TFileName filename( param->Value().AsDes() );
 	        TInt err = KErrNone;
	        TBool result = EFalse;
	        TRAP( err, result = IsPrintingSupportedL( filename ) );
	        if ( err == KErrNone && result )
	        	{
	            FLOG(_L("[CAiwPrintingProvider] DoHandleCmdL; supported file"));
	        	checkedParams->AppendL(*param);
	        	}
	        else
	        	{
	        	FLOG(_L("[CAiwPrintingProvider] DoHandleCmdL; not supported"));
	        	++iNumberOfUnSuppFiles;
	        	iUnsupportedFiles = ETrue;
	        	}	
	        param = aInParamList.FindNext(index,
	            EGenericParamFile,
	            EVariantTypeDesC);
	        }
   
                
		FTRACE(FPrint(_L("[CAiwPrintingProvider] UnSuppFiles is %d"), iNumberOfUnSuppFiles )); 

		RFileWriteStream stream;
	  	CleanupClosePushL(stream);
		if((stream.Replace(iEikEnv.FsSession(), *iUnsuppFileName ,EFileWrite)) == KErrNone)
			{
			stream.WriteInt16L(iNumberOfUnSuppFiles);
			stream.CommitL();
			}
		CleanupStack::PopAndDestroy(&stream); 
		
        FLOG(_L("[IMAGEPRINTUI]<<< CAiwPrintingProvider;Save iUnsupportedFiles  is done"));
	
        
        RFileWriteStream writeStream;
        User::LeaveIfError( writeStream.Replace(iEikEnv.FsSession(),
        										*iPrintFileName , EFileWrite) );
        writeStream.PushL();
        checkedParams->ExternalizeL(writeStream);
        writeStream.CommitL();
        CleanupStack::PopAndDestroy( &writeStream );
        
        iNumberOfUnSuppFiles = 0;
        delete checkedParams;
        checkedParams = NULL;
        
        LaunchImagePrintApplicationL();
        FLOG(_L("[CAiwPrintingProvider]>>> DoHandleCmdL "));
        }
    }