pkiutilities/DeviceToken/Src/Shared/DevTokenDataMarshaller.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2006 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 "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:   Implementation of DevTokenDataMarshaller
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <asymmetric.h>
       
    21 #include <bigint.h>
       
    22 #include <s32mem.h>
       
    23 #include <certificateapps.h>
       
    24 #include <ccertattributefilter.h>
       
    25 #include <s32strm.h>
       
    26 #include <e32test.h>
       
    27 #include "DevTokenMarshaller.h"
       
    28 #include "DevTokenDataTypes.h"
       
    29 #include "DevTokenNullStream.h"
       
    30 #include "DevCertKeyEncryptor.h"
       
    31 #include "DevtokenLog.h"
       
    32 
       
    33 
       
    34 // ======== LOCAL FUNCTIONS ========
       
    35 
       
    36 // Generic externalization stuff
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // Determine how many bytes are taked up by the externalized representation of
       
    40 // an object.
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 template <class T>
       
    44 TInt Size(const T& aObject)
       
    45     {
       
    46     RNullWriteStream stream;
       
    47     TRAPD(err, stream << aObject);
       
    48     if ( err != KErrNone )
       
    49     {
       
    50     _LIT(KPanicCategory, "InValid Size");
       
    51     User::Panic(KPanicCategory,ESerialisationPanic);
       
    52     }
       
    53     stream.Close();
       
    54     return stream.BytesWritten();
       
    55     }
       
    56 
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // Externalize an object to a buffer.  Leaves if an error occurs.
       
    60 // ---------------------------------------------------------------------------
       
    61 // 
       
    62 template <class T>
       
    63 void WriteL(const T& aIn, TDes8& aOut)
       
    64     {
       
    65     RDesWriteStream stream(aOut);
       
    66     stream << aIn;
       
    67     stream.Close();
       
    68     }
       
    69 
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Externalize an object to a buffer.  In debug mode, it will panics if an error
       
    73 // occurs - eg buffer is too short.  In release mode, errors are ignored.
       
    74 // ---------------------------------------------------------------------------
       
    75 //  
       
    76 template <class T>
       
    77 void Write(const T& aIn, TDes8& aOut)
       
    78     {
       
    79     TRAPD(err, WriteL(aIn, aOut));
       
    80     if ( err != KErrNone )
       
    81         {
       
    82         _LIT(KPanicCategory, "Writing Error");
       
    83         User::Panic(KPanicCategory,ESerialisationPanic);
       
    84         }
       
    85     }
       
    86 
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // Implement Externalization selector for RPointerArrays to use a function.
       
    90 // ---------------------------------------------------------------------------
       
    91 // 
       
    92 template <class T>
       
    93 EXTERNALIZE_FUNCTION(RPointerArray<T>)
       
    94 
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // Function to externalize RPointerArrays.Although this is generic, 
       
    98 // it's currently only instantiated for CDevTokenKeyInfo.
       
    99 // ---------------------------------------------------------------------------
       
   100 // 
       
   101 template <class T>
       
   102 void ExternalizeL(const RPointerArray<T>& aIn, RWriteStream& aOut)
       
   103     {
       
   104     TInt count = aIn.Count();
       
   105     aOut.WriteInt32L(count);
       
   106     for ( TInt i = 0 ; i < count ; ++i )
       
   107         {
       
   108         T* object = aIn[i];
       
   109         if ( object == NULL )
       
   110             {
       
   111             User::Leave(KErrArgument);
       
   112             }
       
   113         aOut << *object;
       
   114         }
       
   115     }
       
   116 
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // Implement Externalization selector for RArrays to use a function.
       
   120 // ---------------------------------------------------------------------------
       
   121 //  
       
   122 template <class T>
       
   123 EXTERNALIZE_FUNCTION(RArray<T>)
       
   124 
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // Function to externalize RArrays.
       
   128 // ---------------------------------------------------------------------------
       
   129 //  
       
   130 template <class T>
       
   131 void ExternalizeL(const RArray<T>& aIn, RWriteStream& aOut)
       
   132     {
       
   133     TInt count = aIn.Count();
       
   134     aOut.WriteInt32L(count);
       
   135     for ( TInt i = 0 ; i < count ; ++i )
       
   136         {
       
   137         aOut << aIn[i];
       
   138         }
       
   139     }
       
   140 
       
   141 
       
   142 // No-so-generic internalization stuff 
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // Internalize an object from a descriptor.
       
   146 // ---------------------------------------------------------------------------
       
   147 //  
       
   148 template <class T>
       
   149 void ReadL(const TDesC8& aIn, T& aOut)
       
   150     {
       
   151     RDesReadStream stream(aIn);
       
   152     stream >> aOut;
       
   153     stream.Close();
       
   154     }
       
   155 
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // Implement Internalization selector for RArrays to use a function.
       
   159 // ---------------------------------------------------------------------------
       
   160 //  
       
   161 template <class T>
       
   162 inline Internalize::Function Internalization(const RArray<T>*)
       
   163     {
       
   164     return Internalize::Function();
       
   165     }
       
   166 
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // Function to internalize an RArray.
       
   170 // ---------------------------------------------------------------------------
       
   171 //  
       
   172 template <class T>
       
   173 void InternalizeL(RArray<T>& aOut, RReadStream& aIn)
       
   174     {
       
   175     ASSERT(aOut.Count() == 0);
       
   176     TInt count = aIn.ReadInt32L();
       
   177     for (TInt i = 0 ; i < count ; ++i)
       
   178         {
       
   179         T t;
       
   180         aIn >> t;
       
   181         User::LeaveIfError(aOut.Append(t));
       
   182         }
       
   183     }
       
   184 
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // Internalize an object from a stream.  Creates an instance by calling the
       
   188 // class' NewL(RReadStream&) method.
       
   189 // ---------------------------------------------------------------------------
       
   190 //  
       
   191 template <class T>
       
   192 inline void CreateL(RReadStream& aIn, T*& aOut)
       
   193     {
       
   194     aOut = T::NewL(aIn);
       
   195     }
       
   196 
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // Internalize an object from a descriptor.
       
   200 // ---------------------------------------------------------------------------
       
   201 //  
       
   202 template <class T>
       
   203 void CreateL(const TDesC8& aIn, T& aOut)
       
   204     {
       
   205     RDesReadStream stream(aIn);
       
   206     CreateL(stream, aOut);
       
   207     stream.Close();
       
   208     }
       
   209 
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // Internalize an object from a descriptor leaving the result on the cleanup
       
   213 // stack.  This is generic, but is only instantiated for RInteger.
       
   214 // ---------------------------------------------------------------------------
       
   215 //  
       
   216 template <class T>
       
   217 void CreateLC(const TDesC8& aIn, T& aOut)
       
   218     {
       
   219     RDesReadStream stream(aIn);
       
   220     CreateLC(stream, aOut);
       
   221     stream.Close();
       
   222     }
       
   223 
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // Internalize a cryptotokens object from a descriptor.
       
   227 // ---------------------------------------------------------------------------
       
   228 // 
       
   229 template <class T>
       
   230 void CreateL(const TDesC8& aIn, MCTToken& aToken, T& aOut)
       
   231     {
       
   232     RDesReadStream stream(aIn);
       
   233     CreateL(stream, aToken, aOut);
       
   234     stream.Close();
       
   235     }
       
   236 
       
   237 
       
   238 // ---------------------------------------------------------------------------
       
   239 // Internalize a cryptotoken object from a stream.  Creates an instance by
       
   240 // calling the class' NewL(RReadStream&, MCTToken&) method.
       
   241 // ---------------------------------------------------------------------------
       
   242 // 
       
   243 template <class T>
       
   244 inline void CreateL(RReadStream& aIn, MCTToken& aToken, T*& aOut)
       
   245     {
       
   246     aOut = T::NewL(aIn, aToken);
       
   247     }
       
   248 
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // Internalize an array of of key info objects from a stream. 
       
   252 // ---------------------------------------------------------------------------
       
   253 // 
       
   254 void CreateL(RReadStream& aIn, MCTToken& aToken, MDevTokenKeyInfoArray& aOut)
       
   255     {
       
   256     //No need to check this
       
   257     //ASSERT(aOut.Count() == 0);
       
   258     TInt count = aIn.ReadInt32L();
       
   259     for (TInt i = 0 ; i < count ; ++i)
       
   260         {
       
   261         CCTKeyInfo* t;
       
   262         CreateL(aIn, aToken, t);
       
   263         CleanupReleasePushL(*t);
       
   264         User::LeaveIfError(aOut.Append(t));
       
   265         CleanupStack::Pop();
       
   266         }
       
   267     }
       
   268 
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // Internalize an RMPointerArray of cryptotoken objects from a stream.
       
   272 // ---------------------------------------------------------------------------
       
   273 //  
       
   274 template <class T>
       
   275 void CreateL(RReadStream& aIn, MCTToken& aToken, RMPointerArray<T>& aOut)
       
   276     {
       
   277     TInt count = aIn.ReadInt32L();
       
   278     for (TInt i = 0 ; i < count ; ++i)
       
   279         {
       
   280         T* t;
       
   281         CreateL(aIn, aToken, t);
       
   282         CleanupReleasePushL(*t);
       
   283         User::LeaveIfError(aOut.Append(t));
       
   284         CleanupStack::Pop();
       
   285         }
       
   286     }
       
   287 
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // Internalize an RPointerArray from a stream.
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 template <class T>
       
   294 void CreateL(RReadStream& aIn, RPointerArray<T>& aOut)
       
   295     {
       
   296     TInt count = aIn.ReadInt32L();
       
   297     for (TInt i = 0 ; i < count ; ++i)
       
   298         {
       
   299         T* t;
       
   300         CreateL(aIn, t);
       
   301         CleanupStack::PushL(t);
       
   302         User::LeaveIfError(aOut.Append(t));
       
   303         CleanupStack::Pop();
       
   304         }
       
   305     }
       
   306 
       
   307 // Serialization for RIntegers 
       
   308 // This is exported as it is useful itself in the server
       
   309 
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // Implement a CreateL function for internalizing HBufC8s.
       
   313 // ---------------------------------------------------------------------------
       
   314 // 
       
   315 inline void CreateL(RReadStream& aIn, HBufC8*& aOut)
       
   316     {
       
   317     aOut = HBufC8::NewL(aIn, KMaxIntegerSize);
       
   318     }
       
   319 
       
   320 
       
   321 // ---------------------------------------------------------------------------
       
   322 // Implement a CreateL function for internalizing HBufCs.
       
   323 // ---------------------------------------------------------------------------
       
   324 // 
       
   325 inline void CreateL(RReadStream& aIn, HBufC*& aOut )
       
   326     {
       
   327     aOut = HBufC::NewL(aIn, KMaxSiteName );
       
   328     }
       
   329 
       
   330 
       
   331 // ---------------------------------------------------------------------------
       
   332 // Implement a CreateLC function for internalizing RIntegers.
       
   333 // ---------------------------------------------------------------------------
       
   334 // 
       
   335 EXPORT_C void CreateLC(RReadStream& aIn, RInteger& aOut)
       
   336     {
       
   337     HBufC8* rBuf;
       
   338     CreateL(aIn, rBuf);
       
   339     CleanupStack::PushL(rBuf);
       
   340     TPtr8 rPtr(rBuf->Des());
       
   341     aOut = RInteger::NewL(rPtr);
       
   342     CleanupStack::PopAndDestroy(rBuf);
       
   343     CleanupStack::PushL(aOut);
       
   344     }
       
   345 
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // Decrypt and create a RInteger
       
   349 // ---------------------------------------------------------------------------
       
   350 // 
       
   351 EXPORT_C void DecryptAndCreateLC(RReadStream& aIn, RInteger& aOut, MKeyEncryptor* aEncryptor)
       
   352     {
       
   353     TRACE_PRINT( "DecryptAndCreateL   ->>>")
       
   354     HBufC8* rBuf;
       
   355     HBufC8* decryptedBuf = NULL;
       
   356     CreateL(aIn, rBuf);
       
   357     CleanupStack::PushL(rBuf);
       
   358 
       
   359     TRACE_PRINT( "DecryptAndCreateL encrypted buf:" )
       
   360     TRACE_PRINT_RAW(*rBuf);
       
   361     if ( aEncryptor )
       
   362         {
       
   363         decryptedBuf = aEncryptor->DecryptL( *rBuf );
       
   364 
       
   365         TRACE_PRINT( "DecryptAndCreateL decrypted buf:" )
       
   366         TRACE_PRINT_RAW(*decryptedBuf);
       
   367 
       
   368         TPtr8 decryptedPtr(decryptedBuf->Des());
       
   369         aOut = RInteger::NewL(decryptedPtr);
       
   370         }
       
   371 
       
   372     TRACE_PRINT( "DecryptAndCreatL   <<<-")
       
   373     CleanupStack::PopAndDestroy(rBuf);
       
   374     CleanupStack::PushL(aOut);
       
   375     }
       
   376 
       
   377 
       
   378 // ---------------------------------------------------------------------------
       
   379 // Externalize an RInteger.
       
   380 // ---------------------------------------------------------------------------
       
   381 //  
       
   382 EXPORT_C void ExternalizeL(const TInteger& aIn, RWriteStream& aOut )
       
   383     {
       
   384     HBufC8* sBuf = aIn.BufferLC();
       
   385     aOut << *sBuf;  
       
   386     CleanupStack::PopAndDestroy(sBuf);
       
   387     }
       
   388 
       
   389 
       
   390 // ---------------------------------------------------------------------------
       
   391 // Encrypt and Store an RInteger 
       
   392 // ---------------------------------------------------------------------------
       
   393 //
       
   394 EXPORT_C void EncryptAndStoreL(const TInteger& aIn, RWriteStream& aOut, MKeyEncryptor* aEncryptor )
       
   395     {
       
   396     TRACE_PRINT( "EncryptAndStoreL   ->>>" )
       
   397     
       
   398     HBufC8* sBuf = aIn.BufferLC();
       
   399     HBufC8* encryptedBuf = NULL;
       
   400 
       
   401     TRACE_PRINT( "EncryptAndStoreL plain buf ;")
       
   402     TRACE_PRINT_RAW( *sBuf );
       
   403     if ( aEncryptor )
       
   404         {
       
   405         encryptedBuf = aEncryptor->EncryptL( *sBuf ); 
       
   406         
       
   407         TRACE_PRINT( "EncryptAndStoreL encrypted buf ;" )
       
   408         TRACE_PRINT_RAW( *encryptedBuf );
       
   409         aOut << *encryptedBuf;
       
   410         }
       
   411 
       
   412     TRACE_PRINT( "EncryptAndStoreL   <<<-" )    
       
   413     CleanupStack::PopAndDestroy(sBuf);
       
   414     }
       
   415 
       
   416 
       
   417 // Externalization for signature objects 
       
   418 
       
   419 // ---------------------------------------------------------------------------
       
   420 // Implement Externalization selector for CDSASignature to use a function.
       
   421 // ---------------------------------------------------------------------------
       
   422 //
       
   423 EXTERNALIZE_FUNCTION(CDSASignature)
       
   424 
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // Externalise a DSA signature object.
       
   428 // ---------------------------------------------------------------------------
       
   429 // 
       
   430 void ExternalizeL(const CDSASignature& aIn, RWriteStream& aOut)
       
   431     {
       
   432     aOut << aIn.R();
       
   433     aOut << aIn.S();
       
   434     }
       
   435 
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 // Implement Externalization selector for CRSASignature to use a function.
       
   439 // ---------------------------------------------------------------------------
       
   440 // 
       
   441 EXTERNALIZE_FUNCTION(CRSASignature)
       
   442 
       
   443 
       
   444 // ---------------------------------------------------------------------------
       
   445 // Externalize an RSA signature object.
       
   446 // ---------------------------------------------------------------------------
       
   447 //  
       
   448 void ExternalizeL(const CRSASignature& aIn, RWriteStream& aOut)
       
   449     {
       
   450     aOut << aIn.S();
       
   451     }
       
   452 
       
   453 // Internalization for signature objects ///////////////////////////////////////
       
   454 
       
   455 // ---------------------------------------------------------------------------
       
   456 // Specialise CreateL for CRSASignature.
       
   457 // ---------------------------------------------------------------------------
       
   458 // 
       
   459 template <>
       
   460 void CreateL(RReadStream& aIn, CRSASignature*& aOut)
       
   461     {
       
   462     RInteger r;
       
   463     CreateLC(aIn, r);
       
   464     aOut = CRSASignature::NewL(r);
       
   465     CleanupStack::Pop(); // r
       
   466     }
       
   467 
       
   468 
       
   469 // ---------------------------------------------------------------------------
       
   470 // Specialise CreateL for CDSASignature.
       
   471 // ---------------------------------------------------------------------------
       
   472 // 
       
   473 template <>
       
   474 void CreateL(RReadStream& aIn, CDSASignature*& aOut)
       
   475   {
       
   476     RInteger r;
       
   477     CreateLC(aIn, r);
       
   478     RInteger s;
       
   479     CreateLC(aIn, s);
       
   480     aOut = CDSASignature::NewL(r, s);
       
   481     CleanupStack::Pop(2); // s, r
       
   482     }
       
   483 
       
   484 // Serialization for DH ojects 
       
   485 
       
   486 
       
   487 // ---------------------------------------------------------------------------
       
   488 // Implement Externalization selector for CDevTokenDHParams to use a function.
       
   489 // ---------------------------------------------------------------------------
       
   490 // 
       
   491 EXTERNALIZE_FUNCTION(CDevTokenDHParams)
       
   492 
       
   493 
       
   494 // ---------------------------------------------------------------------------
       
   495 // Externalise a CDevTokenDHParams object.
       
   496 // ---------------------------------------------------------------------------
       
   497 //  
       
   498 void ExternalizeL(const CDevTokenDHParams& aIn, RWriteStream& aOut)
       
   499     {
       
   500     aOut << aIn.N();
       
   501     aOut << aIn.G();
       
   502     }
       
   503 
       
   504 
       
   505 // ---------------------------------------------------------------------------
       
   506 // Specialise CreateL for CDevTokenDHParams.
       
   507 // ---------------------------------------------------------------------------
       
   508 // 
       
   509 template <>
       
   510 void CreateL(RReadStream& aIn, CDevTokenDHParams*& aOut)
       
   511     {
       
   512     RInteger n;
       
   513     CreateLC(aIn, n);
       
   514     RInteger g;
       
   515     CreateLC(aIn, g);
       
   516     aOut = CDevTokenDHParams::NewL(n, g);
       
   517     CleanupStack::PopAndDestroy(2, &n); // g, n
       
   518     }
       
   519 
       
   520 
       
   521 // ---------------------------------------------------------------------------
       
   522 // Implement Externalization selector for CDHPublicKey to use a function.
       
   523 // ---------------------------------------------------------------------------
       
   524 // 
       
   525 EXTERNALIZE_FUNCTION(CDHPublicKey)
       
   526 
       
   527 
       
   528 // ---------------------------------------------------------------------------
       
   529 // Externalise a CDHPublicKey object.
       
   530 // ---------------------------------------------------------------------------
       
   531 //  
       
   532 void ExternalizeL(const CDHPublicKey& aIn, RWriteStream& aOut)
       
   533     {
       
   534     aOut << aIn.N();
       
   535     aOut << aIn.G();
       
   536     aOut << aIn.X();
       
   537     }
       
   538 
       
   539 
       
   540 // ---------------------------------------------------------------------------
       
   541 // Specialise CreateL for CDHPublicKey.
       
   542 // ---------------------------------------------------------------------------
       
   543 // 
       
   544 template <>
       
   545 void CreateL(RReadStream& aIn, CDHPublicKey*& aOut)
       
   546     {
       
   547     RInteger n;
       
   548     CreateLC(aIn, n);
       
   549     RInteger g;
       
   550     CreateLC(aIn, g);
       
   551     RInteger X;
       
   552     CreateLC(aIn, X);
       
   553     aOut = CDHPublicKey::NewL(n, g, X);
       
   554     CleanupStack::Pop(3); // X, g, n
       
   555     }
       
   556 
       
   557 // ======== MEMBER FUNCTIONS ========
       
   558 
       
   559 // Common 
       
   560 
       
   561 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, RArray<TUid>& aOut)
       
   562     {
       
   563     ::ReadL(aIn, aOut);
       
   564     }
       
   565 
       
   566 EXPORT_C TInt DevTokenDataMarshaller::Size(const CKeyInfoBase& aIn)
       
   567     {
       
   568     return ::Size(aIn);
       
   569     }
       
   570 
       
   571 EXPORT_C void DevTokenDataMarshaller::Write(const CKeyInfoBase& aIn, TDes8& aOut)
       
   572     {
       
   573     ::Write(aIn, aOut);
       
   574     }
       
   575 
       
   576 EXPORT_C TInt DevTokenDataMarshaller::Size(const RArray<TUid>& aIn)
       
   577     {
       
   578     return ::Size(aIn);
       
   579     }
       
   580 
       
   581 EXPORT_C void DevTokenDataMarshaller::Write(const RArray<TUid>& aIn, TDes8& aOut)
       
   582     {
       
   583     ::Write(aIn, aOut);
       
   584     }
       
   585 
       
   586 EXPORT_C TInt DevTokenDataMarshaller::Size(const MCertInfo& aIn)
       
   587     {
       
   588     return ::Size(aIn);
       
   589     }
       
   590 
       
   591 EXPORT_C void DevTokenDataMarshaller::Write(const MCertInfo& aIn, TDes8& aOut)
       
   592     {
       
   593     ::Write(aIn, aOut);
       
   594     }
       
   595 
       
   596 // Client 
       
   597 
       
   598 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, MCTToken& aToken, MDevTokenKeyInfoArray& aOut)
       
   599     {
       
   600     ::CreateL(aIn, aToken, aOut);
       
   601     }
       
   602 
       
   603 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, MCTToken& aToken, CCTKeyInfo*& aOut)
       
   604     {
       
   605     ::CreateL(aIn, aToken, aOut);
       
   606     }
       
   607 
       
   608 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, CDSASignature*& aOut)
       
   609     {
       
   610     ::CreateL(aIn, aOut);
       
   611     }
       
   612 
       
   613 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, CRSASignature*& aOut)
       
   614     {
       
   615     ::CreateL(aIn, aOut);
       
   616     }
       
   617 
       
   618 EXPORT_C TInt DevTokenDataMarshaller::Size(const CDevTokenDHParams& aIn)
       
   619     {
       
   620     return Size(aIn.N()) + Size(aIn.G());
       
   621     }
       
   622 
       
   623 EXPORT_C void DevTokenDataMarshaller::WriteL(const CDevTokenDHParams& aIn, TDes8& aOut)
       
   624     {
       
   625     ::WriteL(aIn, aOut);
       
   626     }
       
   627 
       
   628 EXPORT_C TInt DevTokenDataMarshaller::Size(const CDHPublicKey& aIn)
       
   629     {
       
   630     return Size(aIn.N()) + Size(aIn.G()) + Size(aIn.X());
       
   631     }
       
   632 
       
   633 EXPORT_C void DevTokenDataMarshaller::WriteL(const CDHPublicKey& aIn, TDes8& aOut)
       
   634     {
       
   635     ::WriteL(aIn, aOut);
       
   636     }
       
   637 
       
   638 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, RInteger& aInteger)
       
   639     {
       
   640     ::CreateLC(aIn, aInteger);
       
   641     CleanupStack::Pop();
       
   642     }
       
   643 
       
   644 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, MCTToken& aToken, RMPointerArray<CCTCertInfo>& aOut)
       
   645     {
       
   646     ::CreateL(aIn, aToken, aOut);
       
   647     }
       
   648 
       
   649 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, MCTToken& aToken, CCTCertInfo*& aOut)
       
   650     {
       
   651     ::CreateL(aIn, aToken, aOut);
       
   652     }
       
   653 
       
   654 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, RArray<TCertificateAppInfo>& aOut)
       
   655     {
       
   656     ::ReadL(aIn, aOut);
       
   657     }
       
   658 
       
   659 EXPORT_C TInt DevTokenDataMarshaller::Size(const CCertAttributeFilter& aIn)
       
   660     {
       
   661     return ::Size(aIn);
       
   662     }
       
   663 
       
   664 EXPORT_C void DevTokenDataMarshaller::WriteL(const CCertAttributeFilter& aIn, TDes8& aOut)
       
   665     {
       
   666     ::WriteL(aIn, aOut);
       
   667     }
       
   668 
       
   669 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, RPointerArray<HBufC>& aOut)
       
   670     {
       
   671     ::CreateL(aIn, aOut);
       
   672     }
       
   673 
       
   674 // Server 
       
   675 
       
   676 EXPORT_C TInt DevTokenDataMarshaller::Size(const RPointerArray<CDevTokenKeyInfo>& aIn)
       
   677     {
       
   678     return ::Size(aIn);
       
   679     }
       
   680 
       
   681 EXPORT_C TInt DevTokenDataMarshaller::Size(const RPointerArray<HBufC>& aIn)
       
   682     {
       
   683     return ::Size(aIn);
       
   684     } 
       
   685 
       
   686 EXPORT_C void DevTokenDataMarshaller::Write(const RPointerArray<HBufC>& aIn, TDes8& aOut )
       
   687     {
       
   688     return ::Write(aIn, aOut);
       
   689     }
       
   690 
       
   691 EXPORT_C void DevTokenDataMarshaller::Write(const RPointerArray<CDevTokenKeyInfo>& aIn, TDes8& aOut)
       
   692     {
       
   693     ::Write(aIn, aOut);
       
   694     }
       
   695 
       
   696 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, CDevTokenKeyInfo*& aOut)
       
   697     {
       
   698     ::CreateL(aIn, aOut);
       
   699     }
       
   700 
       
   701 
       
   702 // ---------------------------------------------------------------------------
       
   703 // Determine the size of an externalized big integer.  This assumes that the
       
   704 // size of the buffer returned by TInteger::BufferLC() is the same as the size
       
   705 // of the integer as returned by TInteger::ByteCount().  This is done to avoid
       
   706 // allocating the buffer just so we can tell how big it is.
       
   707 // ---------------------------------------------------------------------------
       
   708 // 
       
   709 EXPORT_C TInt DevTokenDataMarshaller::Size(const TInteger& aIn)
       
   710     {
       
   711     // This is an overestimate as the length is encoded with a TCardinality
       
   712     return sizeof(TInt32) + aIn.ByteCount();
       
   713     }
       
   714 
       
   715 EXPORT_C TInt DevTokenDataMarshaller::Size(const CDSASignature& aIn)
       
   716     {
       
   717     return Size(aIn.R()) + Size(aIn.S());
       
   718     }
       
   719 
       
   720 EXPORT_C void DevTokenDataMarshaller::WriteL(const CDSASignature& aIn, TDes8& aOut)
       
   721     {
       
   722     ::WriteL(aIn, aOut);
       
   723     }
       
   724 
       
   725 EXPORT_C TInt DevTokenDataMarshaller::Size(const CRSASignature& aIn)
       
   726     {
       
   727     return Size(aIn.S());
       
   728     }
       
   729 
       
   730 EXPORT_C void DevTokenDataMarshaller::WriteL(const CRSASignature& aIn, TDes8& aOut)
       
   731     {
       
   732     ::WriteL(aIn, aOut);
       
   733     }
       
   734 
       
   735 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, CDevTokenDHParams*& aOut)
       
   736     {
       
   737     ::CreateL(aIn, aOut);
       
   738     }
       
   739 
       
   740 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, CDHPublicKey*& aOut)
       
   741     {
       
   742     ::CreateL(aIn, aOut);
       
   743     }
       
   744 
       
   745 EXPORT_C void DevTokenDataMarshaller::WriteL(const TInteger& aIn, TDes8& aOut)
       
   746     {
       
   747     ::WriteL(aIn, aOut);
       
   748     }
       
   749 
       
   750 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, CDevTokenCertInfo*& aOut)
       
   751     {
       
   752     ::CreateL(aIn, aOut);
       
   753     }
       
   754 
       
   755 EXPORT_C TInt DevTokenDataMarshaller::Size(const RPointerArray<CDevTokenCertInfo>& aIn)
       
   756     {
       
   757     return ::Size(aIn);
       
   758     }
       
   759 
       
   760 EXPORT_C void DevTokenDataMarshaller::Write(const RPointerArray<CDevTokenCertInfo>& aIn, TDes8& aOut)
       
   761     {
       
   762     ::Write(aIn, aOut);
       
   763     }
       
   764 
       
   765 EXPORT_C TInt DevTokenDataMarshaller::Size(const RArray<TCertificateAppInfo>& aIn)
       
   766     {
       
   767     return ::Size(aIn);
       
   768     }
       
   769 
       
   770 EXPORT_C void DevTokenDataMarshaller::Write(const RArray<TCertificateAppInfo>& aIn, TDes8& aOut)
       
   771     {
       
   772     ::Write(aIn, aOut);
       
   773     }
       
   774 
       
   775 EXPORT_C void DevTokenDataMarshaller::ReadL(const TDesC8& aIn, CCertAttributeFilter*& aOut)
       
   776     {
       
   777     ::CreateL(aIn, aOut);
       
   778     }
       
   779 
       
   780 //EOF