persistentstorage/store/UCRYPT/UE_STOR.CPP
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "UE_STD.H"
       
    17 
       
    18 #include <pbe.h>
       
    19 
       
    20 #ifndef __TOOLS2__
       
    21 #include "pbencryptor.h"
       
    22 #endif
       
    23 
       
    24 
       
    25 EXPORT_C CSecureStore* CSecureStore::NewL(CStreamStore& aHost,const CPBEncryptSet& aKey)
       
    26 /**
       
    27 Instantiates a secure store.
       
    28 
       
    29 @leave KErrNoMemory
       
    30 @param aHost The stream store acting as host for the secure store's streams.
       
    31 @param aKey A Password Based Encryption Object used to generate decryption and encryption 
       
    32 handling objects. Ownership of this object remains with the caller who should delete it when it is no longer needed.
       
    33 
       
    34 @return A pointer to the new secure store object.
       
    35 */
       
    36 	{
       
    37 	return new(ELeave) CSecureStore(aHost,aKey);
       
    38 	}
       
    39 
       
    40 EXPORT_C CSecureStore* CSecureStore::NewLC(CStreamStore& aHost,const CPBEncryptSet& aKey)
       
    41 /**
       
    42 Instantiates a secure store and pushes a pointer to the object onto the cleanup stack.
       
    43 
       
    44 @leave KErrNoMemory
       
    45 @param aHost The stream store acting as host for the secure store's streams.
       
    46 @param aKey A Password Based Encryption Object used to generate decryption and encryption 
       
    47 handling objects. Ownership of this object remains with the caller who should delete it when it is no longer needed.
       
    48 
       
    49 @return A pointer to the new secure store object.
       
    50 */
       
    51 	{
       
    52 	CSecureStore* store=NewL(aHost,aKey);
       
    53 	CleanupStack::PushL(store);
       
    54 	return store;
       
    55 	}
       
    56 
       
    57 //	Not exported
       
    58 CSecureStore::CSecureStore(CStreamStore& aHost,const CPBEncryptSet& aKey)
       
    59 	: iHost(&aHost),
       
    60     iKey(aKey)
       
    61 	{}
       
    62 
       
    63 //
       
    64 // Open a stream for reading from the buffer at anId.
       
    65 //
       
    66 EXPORT_C MStreamBuf* CSecureStore::DoReadL(TStreamId anId) const
       
    67 	{
       
    68 	HDecryptFilter* filter=new(ELeave) HDecryptFilter;
       
    69 	CleanupDeletePushL(filter);
       
    70 	RStoreReadStream stream;
       
    71 	stream.OpenLC(Host(),anId);
       
    72 	
       
    73 	CPBDecryptor* decryptor=iKey.NewDecryptLC();
       
    74 	filter->SetL(stream.Source(),decryptor,filter->ERead|filter->EAttached);
       
    75    		
       
    76 	CleanupStack::Pop(3, filter);	//	decryptor, stream, filter 
       
    77 	return filter;
       
    78 	}
       
    79 
       
    80 //	Determine key type and create appropriate encryptor
       
    81 void CSecureStore::setEncryptFilterL(HEncryptFilter& aFilter, RStoreWriteStream& aStream)
       
    82 	{
       
    83 	CPBEncryptor* encryptor=iKey.NewEncryptLC();
       
    84 	aFilter.SetL(aStream.Sink(),encryptor,aFilter.EWrite|aFilter.EAttached);
       
    85 	CleanupStack::Pop(encryptor);
       
    86 	}
       
    87 
       
    88 //
       
    89 // Create a new buffer and open a stream for writing to it.
       
    90 //
       
    91 EXPORT_C MStreamBuf* CSecureStore::DoCreateL(TStreamId& anId)
       
    92 	{
       
    93 	HEncryptFilter* filter=new(ELeave) HEncryptFilter;
       
    94 	CleanupDeletePushL(filter);
       
    95 	RStoreWriteStream stream;
       
    96 	anId=stream.CreateLC(Host());
       
    97 	setEncryptFilterL(*filter, stream);
       
    98 	CleanupStack::Pop(2);	//	stream, filter
       
    99 	return filter;
       
   100 	}
       
   101 
       
   102 EXPORT_C TStreamId CSecureStore::DoExtendL()
       
   103 	{
       
   104 	return Host().ExtendL();
       
   105 	}
       
   106 
       
   107 EXPORT_C void CSecureStore::DoDeleteL(TStreamId anId)
       
   108 	{
       
   109 	Host().DeleteL(anId);
       
   110 	}
       
   111 
       
   112 EXPORT_C MStreamBuf* CSecureStore::DoWriteL(TStreamId anId)
       
   113 	{
       
   114 	HEncryptFilter* filter=new(ELeave) HEncryptFilter;
       
   115 	CleanupDeletePushL(filter);
       
   116 	RStoreWriteStream stream;
       
   117 	stream.OpenLC(Host(), anId);
       
   118 	setEncryptFilterL(*filter, stream);
       
   119 	CleanupStack::Pop(2);	//	stream, filter
       
   120 	return filter;	
       
   121 	}
       
   122 
       
   123 EXPORT_C MStreamBuf* CSecureStore::DoReplaceL(TStreamId anId)
       
   124 	{
       
   125 	HEncryptFilter* filter=new(ELeave) HEncryptFilter;
       
   126 	CleanupDeletePushL(filter);
       
   127 	RStoreWriteStream stream;
       
   128 	stream.ReplaceLC(Host(), anId);
       
   129 	setEncryptFilterL(*filter, stream);
       
   130 	CleanupStack::Pop(2);	//	stream, filter
       
   131 	return filter;	
       
   132 	}
       
   133 
       
   134 EXPORT_C void CSecureStore::DoCommitL()
       
   135 	{
       
   136 	Host().CommitL();
       
   137 	}
       
   138 
       
   139 EXPORT_C void CSecureStore::DoRevertL()
       
   140 	{
       
   141 	Host().RevertL();
       
   142 	}