cms/src/CCMSEncapsulatedContentInfo.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    "CCMSEncapsulatedContentInfo.h"
       
    21 #include <asn1dec.h>
       
    22 #include <asn1enc.h>
       
    23 
       
    24 // CONSTANTS
       
    25 const TInt KMinNumberOfSubModules = 1;
       
    26 const TInt KMaxNumberOfSubModules = 2;
       
    27 const TUint8 KContentTag = 0;
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CCMSEncapsulatedContentInfo::CCMSEncapsulatedContentInfo
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 EXPORT_C CCMSEncapsulatedContentInfo::CCMSEncapsulatedContentInfo()
       
    38     {
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CCMSEncapsulatedContentInfo::ConstructL
       
    43 // Symbian 2nd phase constructor can leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 EXPORT_C void CCMSEncapsulatedContentInfo::ConstructL()
       
    47     {
       
    48 	// creating with empty values
       
    49 	CCMSContentInfo::ConstructL();
       
    50 	SetContentL( NULL );
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CCMSEncapsulatedContentInfo::ConstructL
       
    55 // Symbian 2nd phase constructor can leave.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 EXPORT_C void CCMSEncapsulatedContentInfo::ConstructL(
       
    59 	const TDesC& aContentType,
       
    60 	const TDesC8* aContent )
       
    61     {
       
    62 	CCMSContentInfo::ConstructL( aContentType );
       
    63 	SetContentL( aContent );
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CCMSEncapsulatedContentInfo::NewL
       
    68 // Two-phased constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C CCMSEncapsulatedContentInfo* CCMSEncapsulatedContentInfo::NewL()
       
    72 	{
       
    73 	CCMSEncapsulatedContentInfo* self = NewLC();
       
    74     CleanupStack::Pop( self );
       
    75     return self;
       
    76 	}
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CCMSEncapsulatedContentInfo::NewLC
       
    80 // Two-phased constructor.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C CCMSEncapsulatedContentInfo* CCMSEncapsulatedContentInfo::NewLC()
       
    84 	{
       
    85 	CCMSEncapsulatedContentInfo* self = new( ELeave ) CCMSEncapsulatedContentInfo();
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     return self;
       
    89 	}
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CCMSEncapsulatedContentInfo::NewL
       
    93 // Two-phased constructor.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 EXPORT_C CCMSEncapsulatedContentInfo* CCMSEncapsulatedContentInfo::NewL(
       
    97 	const TDesC& aContentType,
       
    98 	const TDesC8* aContent )
       
    99     {
       
   100     CCMSEncapsulatedContentInfo* self = NewLC( aContentType, aContent );
       
   101     CleanupStack::Pop( self );
       
   102     return self;
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CCMSEncapsulatedContentInfo::NewLC
       
   107 // Two-phased constructor.
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C CCMSEncapsulatedContentInfo* CCMSEncapsulatedContentInfo::NewLC(
       
   111 	const TDesC& aContentType,
       
   112 	const TDesC8* aContent )
       
   113     {
       
   114     CCMSEncapsulatedContentInfo* self = new( ELeave ) CCMSEncapsulatedContentInfo();
       
   115     CleanupStack::PushL( self );
       
   116     self->ConstructL( aContentType, aContent );
       
   117     return self;
       
   118     }
       
   119 
       
   120 // Destructor
       
   121 CCMSEncapsulatedContentInfo::~CCMSEncapsulatedContentInfo()
       
   122     {
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CCMSEncapsulatedContentInfo::DecodeL
       
   127 // Decrypts raw data to this instance
       
   128 // -----------------------------------------------------------------------------
       
   129 void CCMSEncapsulatedContentInfo::DecodeL( const TDesC8& aRawData )
       
   130 	{
       
   131 	CArrayPtr<TASN1DecGeneric>* itemsData = DecodeSequenceLC( aRawData,
       
   132 															  KMinNumberOfSubModules,
       
   133 															  KMaxNumberOfSubModules );
       
   134 	// we would not get this far if there is not atleast one
       
   135 	// decoding attribute type
       
   136 	TASN1DecObjectIdentifier decOid;
       
   137 	HBufC* oid = decOid.DecodeDERL( *itemsData->At( 0 ) );
       
   138 	delete iContentType;
       
   139 	iContentType = oid;
       
   140 
       
   141 	// decoding possible content
       
   142 	HBufC8* contDesc = NULL;
       
   143 	if( itemsData->Count() > 1 )
       
   144 		{
       
   145 		TASN1DecGeneric taggedContent( *itemsData->At( 1 ) );
       
   146 		if( taggedContent.Tag() != KContentTag )
       
   147 			{
       
   148 			User::Leave( KErrArgument );
       
   149 			}
       
   150 		TASN1DecOctetString content;
       
   151 		TInt pos = 0;
       
   152 		contDesc = content.DecodeDERL( taggedContent.GetContentDER(), pos );
       
   153 		}
       
   154 	delete iContent;
       
   155 	iContent = contDesc;
       
   156 	CleanupStack::PopAndDestroy( itemsData );
       
   157 	}
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CCMSEncapsulatedContentInfo::EncoderLC
       
   161 // Returns ASN1 encoder for this instance
       
   162 // -----------------------------------------------------------------------------
       
   163 
       
   164 CASN1EncBase* CCMSEncapsulatedContentInfo::EncoderLC() const
       
   165 	{
       
   166 	CASN1EncSequence* root = CASN1EncSequence::NewLC();
       
   167 
       
   168 	// add attribute type
       
   169 	CASN1EncObjectIdentifier* oid = CASN1EncObjectIdentifier::NewLC( *iContentType );
       
   170 	root->AddAndPopChildL( oid );
       
   171 
       
   172 	// add possible content
       
   173 	if( iContent )
       
   174 		{
       
   175 		CASN1EncOctetString* content = CASN1EncOctetString::NewL( *iContent );
       
   176 		// explicitly tagged to 0
       
   177 		// Takes ownership of the encoder, *including* the case when
       
   178 		// this method leaves.
       
   179 		CASN1EncExplicitTag* explicitTag =
       
   180 			CASN1EncExplicitTag::NewLC( content, KContentTag );
       
   181 		root->AddAndPopChildL( explicitTag );
       
   182 		}
       
   183 	return root;
       
   184 	}
       
   185 // -----------------------------------------------------------------------------
       
   186 // CCMSEncapsulatedContentInfo::Content
       
   187 // Getter for content
       
   188 // -----------------------------------------------------------------------------
       
   189 EXPORT_C const TDesC8* CCMSEncapsulatedContentInfo::Content() const
       
   190 	{
       
   191 	return iContent;
       
   192 	}
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CCMSEncapsulatedContentInfo::SetContentL
       
   196 // Setter for content, takes copy
       
   197 // -----------------------------------------------------------------------------
       
   198 EXPORT_C void CCMSEncapsulatedContentInfo::SetContentL( const TDesC8* aContent )
       
   199 	{
       
   200 	HBufC8* tmp = NULL;
       
   201 	if( aContent )
       
   202 		{
       
   203 		tmp = aContent->AllocL();
       
   204 		}
       
   205 	delete iContent;
       
   206 	iContent = tmp;
       
   207 	}
       
   208 
       
   209 //  End of File