authenticationservices/authenticationserver/source/common/identity.cpp
changeset 29 ece3df019add
equal deleted inserted replaced
19:cd501b96611d 29:ece3df019add
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * CIdentity implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file 
       
    22 */
       
    23 
       
    24 #include "authcommon_impl.h"
       
    25 
       
    26 using namespace AuthServer;
       
    27 
       
    28 EXPORT_C CIdentity* CIdentity::NewL(TIdentityId aId,
       
    29 									CProtectionKey* aKey,
       
    30 									HBufC* aString)
       
    31 	{
       
    32 	CIdentity* me = CIdentity::NewLC(aId, aKey, aString);
       
    33 	CleanupStack::Pop();
       
    34 	return me;
       
    35 	} 
       
    36 
       
    37 EXPORT_C CIdentity* CIdentity::NewLC(TIdentityId aId,
       
    38 									 CProtectionKey* aKey,
       
    39 									 HBufC* aString)
       
    40 	{ 
       
    41 	CIdentity* me = new (ELeave) CIdentity(aId);
       
    42 	CleanupStack::PushL(me);
       
    43 	me->ConstructL(aKey, aString);
       
    44 	return me;
       
    45 	}
       
    46 
       
    47 void CIdentity::ConstructL(CProtectionKey* aKey,
       
    48 						   HBufC* aString)
       
    49     {
       
    50 	iString = aString;
       
    51 	iKey = aKey;
       
    52 	}
       
    53 
       
    54 CIdentity::CIdentity(TIdentityId aId) 
       
    55   : iId(aId)
       
    56     {
       
    57     }
       
    58 
       
    59 CIdentity::~CIdentity()
       
    60 	{
       
    61 	delete iKey;
       
    62 	delete iString;
       
    63 	}
       
    64 	
       
    65 /**
       
    66  * Returns the id number for the identity.
       
    67  *
       
    68  * @return KUnknown if the identity of the device holder could not be
       
    69  * determined.
       
    70  **/
       
    71 EXPORT_C TIdentityId CIdentity::Id() const
       
    72 	{
       
    73 	return iId;
       
    74 	}
       
    75 
       
    76 /**
       
    77  * Returns the protecion key associated with the returned identity. The
       
    78  * key will only be valid if the identity is not unknown.
       
    79  *
       
    80  * @return the protection key of 
       
    81  * the method specified to the RAuthClient::Authenticate method.
       
    82  **/
       
    83 EXPORT_C const CProtectionKey& CIdentity::Key() const
       
    84 	{
       
    85 	return *iKey;
       
    86 	}
       
    87 
       
    88 /**
       
    89  * Returns the string associated with the returned identity. The string will
       
    90  * only be valid if a) the identity is not unknown and b) the identity was
       
    91  * retrieved using the withString parameter of RAuthClient::AuthenticateL set
       
    92  * to true. If this is not the case then an empty string is returned.
       
    93  *
       
    94  * @return the protection key of 
       
    95  * the method specified to the RAuthClient::Authenticate method.
       
    96  **/
       
    97 EXPORT_C TDesC& CIdentity::String() const
       
    98 	{
       
    99 	return *iString;
       
   100 	}
       
   101 
       
   102 EXPORT_C void CIdentity::ExternalizeL(RWriteStream& aWriteStream) const
       
   103     {
       
   104     aWriteStream.WriteInt32L(iId);
       
   105     aWriteStream.WriteInt32L(iKey->KeyData().Length());
       
   106     aWriteStream << iKey->KeyData();
       
   107     aWriteStream<< *iString;
       
   108     }
       
   109  
       
   110 EXPORT_C CIdentity* CIdentity::InternalizeL(RReadStream& aReadStream)
       
   111     {
       
   112     TIdentityId id;
       
   113     id = aReadStream.ReadInt32L();
       
   114     TInt keyLength = aReadStream.ReadInt32L();
       
   115     HBufC8* keydata = HBufC8::NewLC(aReadStream, keyLength);
       
   116     CProtectionKey* prot = CProtectionKey::NewL(keydata);
       
   117     CleanupStack::Pop(keydata);
       
   118 	CleanupStack::PushL(prot);
       
   119 
       
   120     HBufC* stringdata = HBufC::NewLC(aReadStream, KMaxDescLen );
       
   121     CIdentity* identity = CIdentity::NewL(id, prot, stringdata);
       
   122     CleanupStack::Pop(2, prot);
       
   123 	return identity; 
       
   124     }
       
   125