cms/src/CCMSAuthenticatedData.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "CCMSAuthenticatedData.h"
       
    21 #include "CCMSX509AlgorithmIdentifier.h"
       
    22 #include "CCMSOriginatorInfo.h"
       
    23 #include "CCMSRecipientInfo.h"
       
    24 #include "CCMSKeyTransRecipientInfo.h"
       
    25 #include "CCMSKeyAgreeRecipientInfo.h"
       
    26 #include "CCMSKEKRecipientInfo.h"
       
    27 #include "CCMSAttribute.h"
       
    28 #include "CCMSX509Certificate.h"
       
    29 #include "CCMSCertificateChoices.h"
       
    30 #include "CCMSX509CertificateList.h"
       
    31 #include <asn1dec.h>
       
    32 #include <asn1enc.h>
       
    33 
       
    34 // CONSTANTS
       
    35 const TInt KDefaultGranularity = 1;
       
    36 const TInt KMinNumberOfSubModules = 5;
       
    37 const TInt KMaxNumberOfSubModules = 9;
       
    38 const TTagType KOriginatorInfoTag = 0;
       
    39 const TTagType KDigestAlgorithmTag = 1;
       
    40 const TTagType KAuthenticatedAttributesTag = 2;
       
    41 const TTagType KUnauthenticatedAttributesTag = 3;
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // Destructor
       
    46 CCMSAuthenticatedData::CAuthenticatedDataData::~CAuthenticatedDataData()
       
    47     {
       
    48     delete iOriginatorInfo;
       
    49     if( iRecipientInfos )
       
    50         {
       
    51         iRecipientInfos->ResetAndDestroy();
       
    52         delete iRecipientInfos;
       
    53         }
       
    54     delete iMacAlgorithm;
       
    55     delete iDigestAlgorithm;
       
    56     delete iEncapContentInfo;
       
    57     if( iAuthenticatedAttributes )
       
    58         {
       
    59         iAuthenticatedAttributes->ResetAndDestroy();
       
    60         delete iAuthenticatedAttributes;
       
    61         }
       
    62     delete iMac;
       
    63     if( iUnauthenticatedAttributes )
       
    64         {
       
    65         iUnauthenticatedAttributes->ResetAndDestroy();
       
    66         delete iUnauthenticatedAttributes;
       
    67         }
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CCMSAuthenticatedData::CCMSAuthenticatedData
       
    72 // C++ default constructor can NOT contain any code, that
       
    73 // might leave.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 EXPORT_C CCMSAuthenticatedData::CCMSAuthenticatedData( )
       
    77     {
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CCMSAuthenticatedData::ConstructL
       
    82 // Symbian 2nd phase constructor can leave.
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C void CCMSAuthenticatedData::ConstructL(
       
    86     CArrayPtr< CCMSRecipientInfo >* aRecipientInfos,
       
    87     CCMSX509AlgorithmIdentifier* aMacAlgorithm,
       
    88     CCMSEncapsulatedContentInfo* aEncapContentInfo,
       
    89     const TDesC8& aMac )
       
    90     {
       
    91     iData = new( ELeave ) CAuthenticatedDataData;
       
    92     iData->iMac = aMac.AllocL();
       
    93     
       
    94     // all memory allocations have been done, we can take ownerships
       
    95     iData->iRecipientInfos = aRecipientInfos;
       
    96     iData->iMacAlgorithm = aMacAlgorithm;
       
    97     iData->iEncapContentInfo = aEncapContentInfo;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CCMSAuthenticatedData::ConstructL
       
   102 // Symbian 2nd phase constructor can leave.
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 EXPORT_C void CCMSAuthenticatedData::ConstructL( )
       
   106     {
       
   107     // creating empty/default values
       
   108     iData = new( ELeave ) CAuthenticatedDataData;
       
   109     iData->iRecipientInfos =
       
   110         new( ELeave ) CArrayPtrFlat< CCMSRecipientInfo >( KDefaultGranularity );
       
   111     iData->iMacAlgorithm = CCMSX509AlgorithmIdentifier::NewL();
       
   112     iData->iEncapContentInfo = CCMSEncapsulatedContentInfo::NewL();
       
   113     iData->iMac = KNullDesC8().AllocL();
       
   114     }
       
   115     
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CCMSAuthenticatedData::NewLC
       
   119 // Two-phased constructor.
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 EXPORT_C CCMSAuthenticatedData*
       
   123 CCMSAuthenticatedData::NewLC()
       
   124 	{
       
   125 	// creating with empty values
       
   126     CCMSAuthenticatedData* self =
       
   127         new( ELeave ) CCMSAuthenticatedData();
       
   128     CleanupStack::PushL( self );
       
   129     self->ConstructL( );
       
   130 	return self;
       
   131 	}
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CCMSAuthenticatedData::NewLC
       
   135 // Two-phased constructor.
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 EXPORT_C CCMSAuthenticatedData*
       
   139 CCMSAuthenticatedData::NewLC(
       
   140     CArrayPtr< CCMSRecipientInfo >* aRecipientInfos,
       
   141     CCMSX509AlgorithmIdentifier* aMacAlgorithm,
       
   142     CCMSEncapsulatedContentInfo* aEncapContentInfo,
       
   143     const TDesC8& aMac )
       
   144     {
       
   145     CCMSAuthenticatedData* self =
       
   146         new( ELeave ) CCMSAuthenticatedData();
       
   147     CleanupStack::PushL( self );
       
   148     self->ConstructL( aRecipientInfos, aMacAlgorithm, aEncapContentInfo, aMac );
       
   149 
       
   150     return self;
       
   151     }
       
   152 
       
   153 // Destructor
       
   154 CCMSAuthenticatedData::~CCMSAuthenticatedData()
       
   155     {
       
   156 	delete iData;
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CCMSAuthenticatedData::DecodeL
       
   161 // Decrypts raw data to this instance
       
   162 // -----------------------------------------------------------------------------
       
   163 void CCMSAuthenticatedData::DecodeL( const TDesC8& aRawData )
       
   164 	{
       
   165     CArrayPtr< TASN1DecGeneric >* items = DecodeSequenceLC(
       
   166         aRawData, KMinNumberOfSubModules, KMaxNumberOfSubModules );
       
   167 
       
   168     // now we know that there are at least 5 items
       
   169     TInt itemCount = items->Count();
       
   170     __ASSERT_DEBUG( itemCount >= KMinNumberOfSubModules, User::Invariant() );
       
   171     
       
   172     TInt sequenceCounter = 0;
       
   173 
       
   174     CAuthenticatedDataData* data = new( ELeave ) CAuthenticatedDataData;
       
   175     CleanupStack::PushL( data );
       
   176     
       
   177     // decode version
       
   178     TASN1DecInteger intDecoder;
       
   179     data->iVersion =
       
   180         intDecoder.DecodeDERShortL( *items->At( sequenceCounter++ ) );
       
   181 
       
   182     // decode originatorInfo, if exist
       
   183     TASN1DecGeneric* originatorInfoDecoder = items->At( sequenceCounter );
       
   184     if( originatorInfoDecoder->Tag() == KOriginatorInfoTag )
       
   185         {
       
   186         data->iOriginatorInfo = CCMSOriginatorInfo::NewL();
       
   187         data->iOriginatorInfo->DecodeImplicitTagL(
       
   188             originatorInfoDecoder->Encoding(), KOriginatorInfoTag );
       
   189         sequenceCounter++;
       
   190         }
       
   191 
       
   192     // decode recipientInfos
       
   193     CArrayPtr< TASN1DecGeneric >* recipientInfos = DecodeSequenceLC(
       
   194         items->At( sequenceCounter++)->Encoding() );
       
   195     TInt recipientInfoCount = recipientInfos->Count();
       
   196     data->iRecipientInfos =
       
   197         new( ELeave ) CArrayPtrFlat< CCMSRecipientInfo >( recipientInfoCount );
       
   198     for( TInt i = 0; i < recipientInfoCount; i++ )
       
   199         {
       
   200         TASN1DecGeneric* recipientInfoDecoder = recipientInfos->At( i );
       
   201         CCMSRecipientInfo* recipientInfo = NULL;
       
   202         switch( recipientInfoDecoder->Tag() )
       
   203             {
       
   204             case EASN1Sequence:
       
   205                 {
       
   206                 recipientInfo = CCMSKeyTransRecipientInfo::NewLC();
       
   207                 recipientInfo->DecodeL( recipientInfoDecoder->Encoding() );
       
   208                 break;
       
   209                 }
       
   210             case KCMSKeyAgreeRecipientInfoTag:
       
   211                 {
       
   212                 recipientInfo = CCMSKeyAgreeRecipientInfo::NewLC();
       
   213                 recipientInfo->DecodeL( recipientInfoDecoder->Encoding() );
       
   214                 break;
       
   215                 }
       
   216             case KCMSKEKRecipientInfoTag:
       
   217                 {
       
   218                 recipientInfo = CCMSKEKRecipientInfo::NewLC();
       
   219                 recipientInfo->DecodeL( recipientInfoDecoder->Encoding() );
       
   220                 break;
       
   221                 }
       
   222             default:
       
   223                 {
       
   224                 User::Leave( KErrArgument );
       
   225                 }
       
   226             }
       
   227         data->iRecipientInfos->AppendL( recipientInfo );
       
   228         CleanupStack::Pop( recipientInfo );
       
   229         }
       
   230     CleanupStack::PopAndDestroy( recipientInfos );
       
   231     
       
   232     // decode macAlgorithm
       
   233     data->iMacAlgorithm = CCMSX509AlgorithmIdentifier::NewL();
       
   234     data->iMacAlgorithm->DecodeL( items->At( sequenceCounter++)->Encoding() );
       
   235 
       
   236     // decode digestAlgorithm, if exist
       
   237     TASN1DecGeneric* digestAlgorithmDec = items->At( sequenceCounter );
       
   238     if( digestAlgorithmDec->Tag() == KDigestAlgorithmTag )
       
   239         {
       
   240         data->iDigestAlgorithm = CCMSX509AlgorithmIdentifier::NewL();
       
   241         data->iDigestAlgorithm->DecodeL( digestAlgorithmDec->GetContentDER() );
       
   242         sequenceCounter++;
       
   243         }
       
   244 
       
   245     // decode encapContentInfo
       
   246     if( sequenceCounter == itemCount )
       
   247         {
       
   248         User::Leave( KErrArgument );
       
   249         }
       
   250     data->iEncapContentInfo = CCMSEncapsulatedContentInfo::NewL();
       
   251     data->iEncapContentInfo->DecodeL(
       
   252         items->At( sequenceCounter++)->Encoding() );
       
   253 
       
   254     // decode authenticatedAttributes, if exist
       
   255     if( sequenceCounter == itemCount )
       
   256         {
       
   257         User::Leave( KErrArgument );
       
   258         }
       
   259     TASN1DecGeneric* authAttributesDec = items->At( sequenceCounter );
       
   260     if( authAttributesDec->Tag() == KAuthenticatedAttributesTag )
       
   261         {
       
   262         data->iAuthenticatedAttributes = DecodeAttributesL( authAttributesDec );
       
   263         sequenceCounter++;
       
   264         }
       
   265 
       
   266     // decode mac
       
   267     if( sequenceCounter == itemCount )
       
   268         {
       
   269         User::Leave( KErrArgument );
       
   270         }
       
   271     TASN1DecOctetString octetStrDec;
       
   272     data->iMac = octetStrDec.DecodeDERL( *( items->At( sequenceCounter++ ) ) );
       
   273 
       
   274     // decode unauthenticatedAttributes, if exist
       
   275     if( itemCount > sequenceCounter )
       
   276         {
       
   277         TASN1DecGeneric* unauthAttributesDec = items->At( sequenceCounter );
       
   278         if( unauthAttributesDec->Tag() != KUnauthenticatedAttributesTag )
       
   279             {
       
   280             User::Leave( KErrArgument );
       
   281             }
       
   282         data->iUnauthenticatedAttributes =
       
   283             DecodeAttributesL( unauthAttributesDec );
       
   284         }
       
   285 
       
   286     // all done, change state
       
   287     CleanupStack::Pop( data );
       
   288     CleanupStack::PopAndDestroy( items );
       
   289     delete iData;
       
   290     iData = data;
       
   291 	}
       
   292 
       
   293 
       
   294 
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CCMSAuthenticatedData::EncoderLC
       
   298 // Returns ASN1 encoder for this instance
       
   299 // -----------------------------------------------------------------------------
       
   300 CASN1EncBase* CCMSAuthenticatedData::EncoderLC() const
       
   301 	{
       
   302     CASN1EncSequence* root = CASN1EncSequence::NewLC();
       
   303 
       
   304     // encode version
       
   305     CASN1EncInt* version = CASN1EncInt::NewLC( iData->iVersion );
       
   306     root->AddAndPopChildL( version );
       
   307 
       
   308     // encode originatorInfo, if exist
       
   309     if( iData->iOriginatorInfo )
       
   310         {
       
   311         CASN1EncBase* originatorInfo = iData->iOriginatorInfo->EncoderLC();
       
   312         originatorInfo->SetTag( KOriginatorInfoTag );
       
   313         root->AddAndPopChildL( originatorInfo );
       
   314         }
       
   315 
       
   316     // encode recipientInfos ::= SET OF RecipientInfo
       
   317     CASN1EncSequence* recipientInfos = CASN1EncSequence::NewLC();
       
   318     TInt recipientInfoCount = iData->iRecipientInfos->Count();
       
   319     TInt i = 0;
       
   320     for( ; i < recipientInfoCount; i++ )
       
   321         {
       
   322         CASN1EncBase* recipientInfo =
       
   323             iData->iRecipientInfos->At( i )->TaggedEncoderLC();
       
   324         recipientInfos->AddAndPopChildL( recipientInfo );
       
   325         }
       
   326     recipientInfos->SetTag( EASN1Set, EUniversal );
       
   327     root->AddAndPopChildL( recipientInfos );
       
   328     
       
   329     // encode macAlgorithm
       
   330     CASN1EncBase* macAlgorithm = iData->iMacAlgorithm->EncoderLC();
       
   331     root->AddAndPopChildL( macAlgorithm );
       
   332 
       
   333     // encode digestAlgorithm, if exist
       
   334     if( iData->iDigestAlgorithm )
       
   335         {
       
   336         CASN1EncBase* digestAlgorithm = iData->iDigestAlgorithm->EncoderLC();
       
   337         CleanupStack::Pop( digestAlgorithm );
       
   338         
       
   339         // CASN1EncExplicitTag takes ownership of the parameter, even
       
   340         // if the method leaves.
       
   341         CASN1EncExplicitTag* taggedDigestAlgorithm =
       
   342             CASN1EncExplicitTag::NewLC( digestAlgorithm, KDigestAlgorithmTag );
       
   343         root->AddAndPopChildL( taggedDigestAlgorithm );
       
   344         }
       
   345 
       
   346     // encode encapContentInfo
       
   347     CASN1EncBase* encapContentInfo = iData->iEncapContentInfo->EncoderLC();
       
   348     root->AddAndPopChildL( encapContentInfo );
       
   349 
       
   350     // encode authenticatedAttributes, if exist
       
   351     if( iData->iAuthenticatedAttributes )
       
   352         {
       
   353         CASN1EncSequence* authAttributes = CASN1EncSequence::NewLC();
       
   354         TInt authAttributeCount = iData->iAuthenticatedAttributes->Count();
       
   355         for( i = 0; i < authAttributeCount; i++ )
       
   356             {
       
   357             CASN1EncBase* attribute =
       
   358                 iData->iAuthenticatedAttributes->At( i )->EncoderLC();
       
   359             authAttributes->AddAndPopChildL( attribute );
       
   360             }
       
   361         authAttributes->SetTag( KAuthenticatedAttributesTag );
       
   362         root->AddAndPopChildL( authAttributes );
       
   363         }
       
   364 
       
   365     // encode mac
       
   366     CASN1EncOctetString* mac = CASN1EncOctetString::NewLC( *iData->iMac );
       
   367     root->AddAndPopChildL( mac );
       
   368     
       
   369     // encode unauthenticatedAttributes, if exist
       
   370     if( iData->iUnauthenticatedAttributes )
       
   371         {
       
   372         CASN1EncSequence* unauthAttributes = CASN1EncSequence::NewLC();
       
   373         TInt unauthAttributeCount = iData->iUnauthenticatedAttributes->Count();
       
   374         for( i = 0; i < unauthAttributeCount; i++ )
       
   375             {
       
   376             CASN1EncBase* attribute =
       
   377                 iData->iUnauthenticatedAttributes->At( i )->EncoderLC();
       
   378             unauthAttributes->AddAndPopChildL( attribute );
       
   379             }
       
   380         unauthAttributes->SetTag( KUnauthenticatedAttributesTag );
       
   381         root->AddAndPopChildL( unauthAttributes );
       
   382         }
       
   383     
       
   384     return root;
       
   385     }
       
   386 
       
   387 // -----------------------------------------------------------------------------
       
   388 // CCMSAuthenticatedData::Version()
       
   389 // Getter for Version
       
   390 // -----------------------------------------------------------------------------
       
   391 EXPORT_C TInt CCMSAuthenticatedData::Version() const
       
   392 	{
       
   393 	return iData->iVersion;
       
   394 	}
       
   395 
       
   396 // -----------------------------------------------------------------------------
       
   397 // CCMSAuthenticatedData::OriginatorInfo()
       
   398 // Getter for OriginatorInfo
       
   399 // -----------------------------------------------------------------------------
       
   400 EXPORT_C const CCMSOriginatorInfo* CCMSAuthenticatedData::OriginatorInfo() const
       
   401 	{
       
   402 	return iData->iOriginatorInfo;
       
   403 	}
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // CCMSAuthenticatedData::RecipientInfos()
       
   407 // Getter for recipientInfos
       
   408 // -----------------------------------------------------------------------------
       
   409 EXPORT_C const CArrayPtr< CCMSRecipientInfo >&
       
   410 CCMSAuthenticatedData::RecipientInfos() const
       
   411 	{
       
   412 	return *( iData->iRecipientInfos );
       
   413 	}
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // CCMSAuthenticatedData::MacAlgorithm()
       
   417 // Getter for macAlgorithm
       
   418 // -----------------------------------------------------------------------------
       
   419 EXPORT_C const CCMSX509AlgorithmIdentifier&
       
   420 CCMSAuthenticatedData::MacAlgorithm() const
       
   421 	{
       
   422 	return *( iData->iMacAlgorithm );
       
   423 	}
       
   424 
       
   425 // -----------------------------------------------------------------------------
       
   426 // CCMSAuthenticatedData::DigestAlgorithm()
       
   427 // Getter for digestAlgorithm
       
   428 // -----------------------------------------------------------------------------
       
   429 EXPORT_C const CCMSX509AlgorithmIdentifier*
       
   430 CCMSAuthenticatedData::DigestAlgorithm() const
       
   431 	{
       
   432 	return iData->iDigestAlgorithm;
       
   433 	}
       
   434 
       
   435 // -----------------------------------------------------------------------------
       
   436 // CCMSAuthenticatedData::EncapContentInfo()
       
   437 // Getter for encapContentInfo
       
   438 // -----------------------------------------------------------------------------
       
   439 EXPORT_C const CCMSEncapsulatedContentInfo&
       
   440 CCMSAuthenticatedData::EncapContentInfo() const
       
   441 	{
       
   442 	return *( iData->iEncapContentInfo );
       
   443 	}
       
   444 
       
   445 // -----------------------------------------------------------------------------
       
   446 // CCMSAuthenticatedData::AuthenticatedAttributes()
       
   447 // Getter for authenticatedAttributes
       
   448 // -----------------------------------------------------------------------------
       
   449 EXPORT_C const CArrayPtr< CCMSAttribute >*
       
   450 CCMSAuthenticatedData::AuthenticatedAttributes() const
       
   451 	{
       
   452 	return iData->iAuthenticatedAttributes;
       
   453 	}
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 // CCMSAuthenticatedData::Mac()
       
   457 // Getter for mac
       
   458 // -----------------------------------------------------------------------------
       
   459 EXPORT_C const TDesC8& CCMSAuthenticatedData::Mac() const
       
   460 	{
       
   461 	return *( iData->iMac );
       
   462 	}
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CCMSAuthenticatedData::UnauthenticatedAttributes()
       
   466 // Getter for unauthenticatedAttributes
       
   467 // -----------------------------------------------------------------------------
       
   468 EXPORT_C const CArrayPtr< CCMSAttribute >*
       
   469 CCMSAuthenticatedData::UnauthenticatedAttributes() const
       
   470 	{
       
   471 	return iData->iUnauthenticatedAttributes;
       
   472 	}
       
   473 
       
   474 // -----------------------------------------------------------------------------
       
   475 // CCMSAuthenticatedData::SetVersion()
       
   476 // Setter for version
       
   477 // -----------------------------------------------------------------------------
       
   478 EXPORT_C void CCMSAuthenticatedData::SetVersion( TInt aVersion )
       
   479 	{
       
   480     iData->iVersion = aVersion;
       
   481 	}
       
   482 
       
   483 // -----------------------------------------------------------------------------
       
   484 // CCMSAuthenticatedData::SetOriginatorInfoL()
       
   485 // Setter for OriginatorInfo
       
   486 // -----------------------------------------------------------------------------
       
   487 EXPORT_C void CCMSAuthenticatedData::SetOriginatorInfoL(
       
   488     CCMSOriginatorInfo* aOriginatorInfo )
       
   489 	{
       
   490     delete iData->iOriginatorInfo;
       
   491     iData->iOriginatorInfo = aOriginatorInfo;
       
   492 	}
       
   493 
       
   494 // -----------------------------------------------------------------------------
       
   495 // CCMSAuthenticatedData::SetRecipientInfosL()
       
   496 // Setter for recipientInfos
       
   497 // -----------------------------------------------------------------------------
       
   498 EXPORT_C void CCMSAuthenticatedData::SetRecipientInfosL(
       
   499     CArrayPtr< CCMSRecipientInfo >* aRecipientInfos )
       
   500 	{
       
   501     if( ( !aRecipientInfos ) || ( aRecipientInfos->Count() == 0 ) )
       
   502         {
       
   503         User::Leave( KErrArgument );
       
   504         }
       
   505     
       
   506     if( iData->iRecipientInfos )
       
   507         {
       
   508         iData->iRecipientInfos->ResetAndDestroy();
       
   509         delete iData->iRecipientInfos;
       
   510         }
       
   511     iData->iRecipientInfos = aRecipientInfos;
       
   512 	}
       
   513 
       
   514 // -----------------------------------------------------------------------------
       
   515 // CCMSAuthenticatedData::SetMacAlgorithmL()
       
   516 // Setter for macAlgorithm
       
   517 // -----------------------------------------------------------------------------
       
   518 EXPORT_C void CCMSAuthenticatedData::SetMacAlgorithmL(
       
   519     CCMSX509AlgorithmIdentifier* aMacAlgorithm )
       
   520 	{
       
   521     if( !aMacAlgorithm )
       
   522         {
       
   523         User::Leave( KErrArgument );
       
   524         }
       
   525     delete iData->iMacAlgorithm;
       
   526     iData->iMacAlgorithm = aMacAlgorithm;
       
   527 	}
       
   528 
       
   529 // -----------------------------------------------------------------------------
       
   530 // CCMSAuthenticatedData::SetDigestAlgorithmL()
       
   531 // Setter for digestAlgorithm
       
   532 // -----------------------------------------------------------------------------
       
   533 EXPORT_C void CCMSAuthenticatedData::SetDigestAlgorithmL(
       
   534     CCMSX509AlgorithmIdentifier* aDigestAlgorithm )
       
   535 	{
       
   536     delete iData->iDigestAlgorithm;
       
   537     iData->iDigestAlgorithm = aDigestAlgorithm;
       
   538 	}
       
   539 
       
   540 // -----------------------------------------------------------------------------
       
   541 // CCMSAuthenticatedData::SetEncapContentInfoL()
       
   542 // Setter for encapContentInfo
       
   543 // -----------------------------------------------------------------------------
       
   544 EXPORT_C void CCMSAuthenticatedData::SetEncapContentInfoL(
       
   545     CCMSEncapsulatedContentInfo* aEncapContentInfo )
       
   546 	{
       
   547     if( !aEncapContentInfo )
       
   548         {
       
   549         User::Leave( KErrArgument );
       
   550         }
       
   551     delete iData->iEncapContentInfo;
       
   552     iData->iEncapContentInfo = aEncapContentInfo;
       
   553 	}
       
   554 
       
   555 // -----------------------------------------------------------------------------
       
   556 // CCMSAuthenticatedData::SetAuthenticatedAttributesL()
       
   557 // Setter for authenticatedAttributes
       
   558 // -----------------------------------------------------------------------------
       
   559 EXPORT_C void CCMSAuthenticatedData::SetAuthenticatedAttributesL(
       
   560     CArrayPtr< CCMSAttribute >* aAuthenticatedAttributes )
       
   561 	{
       
   562     if( iData->iAuthenticatedAttributes )
       
   563         {
       
   564         iData->iAuthenticatedAttributes->ResetAndDestroy();
       
   565         delete iData->iAuthenticatedAttributes;
       
   566         }
       
   567     iData->iAuthenticatedAttributes = aAuthenticatedAttributes;
       
   568 	}
       
   569 
       
   570 // -----------------------------------------------------------------------------
       
   571 // CCMSAuthenticatedData::SetMacL
       
   572 // Setter for mac
       
   573 // -----------------------------------------------------------------------------
       
   574 EXPORT_C void CCMSAuthenticatedData::SetMacL(
       
   575     const TDesC8& aMac)
       
   576 	{
       
   577     HBufC8* mac = aMac.AllocL();
       
   578     delete iData->iMac;
       
   579     iData->iMac = mac;
       
   580 	}
       
   581 
       
   582 // -----------------------------------------------------------------------------
       
   583 // CCMSAuthenticatedData::SetUnauthenticatedAttributesL()
       
   584 // Setter for unauthenticatedAttributes
       
   585 // -----------------------------------------------------------------------------
       
   586 EXPORT_C void CCMSAuthenticatedData::SetUnauthenticatedAttributesL(
       
   587     CArrayPtr< CCMSAttribute >* aUnauthenticatedAttributes )
       
   588 	{
       
   589     if( iData->iUnauthenticatedAttributes )
       
   590         {
       
   591         iData->iUnauthenticatedAttributes->ResetAndDestroy();
       
   592         delete iData->iUnauthenticatedAttributes;
       
   593         }
       
   594     iData->iUnauthenticatedAttributes = aUnauthenticatedAttributes;
       
   595 	}
       
   596 
       
   597 // -----------------------------------------------------------------------------
       
   598 // CCMSAuthenticatedData::DecodeAttributesL
       
   599 // Decodes an array of attributes
       
   600 // -----------------------------------------------------------------------------
       
   601 CArrayPtrFlat< CCMSAttribute >* CCMSAuthenticatedData::DecodeAttributesL(
       
   602     TASN1DecGeneric* aAttributesDec ) // generic decoder for the sequence
       
   603     {
       
   604     TASN1DecSequence sequenceDecoder;
       
   605     CArrayPtr< TASN1DecGeneric >* attributes =
       
   606         sequenceDecoder.DecodeDERLC( *aAttributesDec );
       
   607     TInt attributeCount = attributes->Count();
       
   608     if( attributeCount <  1 )
       
   609         {
       
   610         User::Leave( KErrArgument );
       
   611         }
       
   612     CArrayPtrFlat< CCMSAttribute >* retVal =
       
   613         new( ELeave ) CArrayPtrFlat< CCMSAttribute >( attributeCount );
       
   614     CleanupStack::PushL( retVal );
       
   615     for( TInt i = 0; i < attributeCount; i++ )
       
   616         {
       
   617         CCMSAttribute* attribute = CCMSAttribute::NewLC();
       
   618         attribute->DecodeL( attributes->At( i )->Encoding() );
       
   619         retVal->AppendL( attribute );
       
   620         // attribute is left in cleanup stack, as retVal has not been pushed
       
   621         // with ResetAndDestroyPushL
       
   622         }
       
   623     CleanupStack::Pop( attributeCount ); // all attributes
       
   624     CleanupStack::Pop( retVal );
       
   625     CleanupStack::PopAndDestroy( attributes );
       
   626     return retVal;
       
   627     }
       
   628 
       
   629 //  End of File