sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: EXPORT_C CASN1EncEncoding::~CASN1EncEncoding() sl@0: { sl@0: delete iContents; sl@0: } sl@0: sl@0: // Set arbitrary initial values for tag type and class because they will be sl@0: // inited in ConstructL(). sl@0: EXPORT_C CASN1EncEncoding::CASN1EncEncoding() : sl@0: CASN1EncBase(EASN1EOC, EUniversal) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CASN1EncEncoding* CASN1EncEncoding::NewLC(const TDesC8& aEncoding) sl@0: { sl@0: CASN1EncEncoding* self = new (ELeave) CASN1EncEncoding; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aEncoding); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CASN1EncEncoding* CASN1EncEncoding::NewL(const TDesC8& aEncoding) sl@0: { sl@0: CASN1EncEncoding* self = NewLC(aEncoding); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CASN1EncEncoding* CASN1EncEncoding::NewLC(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass) sl@0: { sl@0: CASN1EncEncoding* self = new (ELeave) CASN1EncEncoding; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aEncoding, aType, aClass); sl@0: return self; sl@0: } sl@0: sl@0: void CASN1EncEncoding::ConstructL(const TDesC8& aEncoding) sl@0: { sl@0: // Use decoder to get information about the outer wrapper of the passed sl@0: // encoding. sl@0: TASN1DecGeneric decoder(aEncoding); sl@0: decoder.InitL(); sl@0: iClass = decoder.Class(); sl@0: iTag = decoder.Tag(); sl@0: // Set this information so that the base class knows how to write sl@0: // DER encoding. sl@0: SetTag(iTag, iClass); sl@0: // Copy just the contents of the passed encoding. sl@0: iContents = decoder.GetContentDER().AllocL(); sl@0: // Save this for base class writing functions. sl@0: iContentsLengthDER = iContents->Length(); sl@0: // This is base class' method which initializes length of length sl@0: // encoding for proper DER writing. sl@0: CalculateLengthLengthDER(); sl@0: } sl@0: sl@0: void CASN1EncEncoding::ConstructL(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass) sl@0: { sl@0: // Use decoder to get information about the outer wrapper of the passed sl@0: // encoding. sl@0: TASN1DecGeneric decoder(aEncoding); sl@0: decoder.InitL(); sl@0: iClass = aClass; sl@0: iTag = aType; sl@0: // Set this information so that the base class knows how to write sl@0: // DER encoding. sl@0: SetTag(aType, aClass); sl@0: // Copy just the contents of the passed encoding. sl@0: iContents = decoder.GetContentDER().AllocL(); sl@0: // Save this for base class writing functions. sl@0: iContentsLengthDER = iContents->Length(); sl@0: // This is base class' method which initializes length of length sl@0: // encoding for proper DER writing. sl@0: CalculateLengthLengthDER(); sl@0: } sl@0: sl@0: sl@0: // This method is not called but is necessary because it overrides a sl@0: // pure virtual function of the base class. The variable is properly sl@0: // initialized in ConstructL(). sl@0: void CASN1EncEncoding::CalculateContentsLengthDER() sl@0: { sl@0: iContentsLengthDER = iContents->Length(); sl@0: } sl@0: sl@0: TBool CASN1EncEncoding::IsConstructed() const sl@0: { sl@0: return ETrue; sl@0: } sl@0: sl@0: // When this method is called by the base class write helper, the tag sl@0: // and length are already written. sl@0: void CASN1EncEncoding::WriteContentsDERL(TDes8& aBuf) const sl@0: { sl@0: aBuf.Copy(*iContents); sl@0: }