1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/asn1/encenc.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,122 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 +*/
1.25 +
1.26 +#include <e32std.h>
1.27 +#include <e32def.h>
1.28 +#include <asn1enc.h>
1.29 +#include <asn1dec.h>
1.30 +
1.31 +EXPORT_C CASN1EncEncoding::~CASN1EncEncoding()
1.32 + {
1.33 + delete iContents;
1.34 + }
1.35 +
1.36 +// Set arbitrary initial values for tag type and class because they will be
1.37 +// inited in ConstructL().
1.38 +EXPORT_C CASN1EncEncoding::CASN1EncEncoding() :
1.39 + CASN1EncBase(EASN1EOC, EUniversal)
1.40 + {
1.41 + }
1.42 +
1.43 +EXPORT_C CASN1EncEncoding* CASN1EncEncoding::NewLC(const TDesC8& aEncoding)
1.44 + {
1.45 + CASN1EncEncoding* self = new (ELeave) CASN1EncEncoding;
1.46 + CleanupStack::PushL(self);
1.47 + self->ConstructL(aEncoding);
1.48 + return self;
1.49 + }
1.50 +
1.51 +EXPORT_C CASN1EncEncoding* CASN1EncEncoding::NewL(const TDesC8& aEncoding)
1.52 + {
1.53 + CASN1EncEncoding* self = NewLC(aEncoding);
1.54 + CleanupStack::Pop(self);
1.55 + return self;
1.56 + }
1.57 +
1.58 +EXPORT_C CASN1EncEncoding* CASN1EncEncoding::NewLC(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass)
1.59 + {
1.60 + CASN1EncEncoding* self = new (ELeave) CASN1EncEncoding;
1.61 + CleanupStack::PushL(self);
1.62 + self->ConstructL(aEncoding, aType, aClass);
1.63 + return self;
1.64 + }
1.65 +
1.66 +void CASN1EncEncoding::ConstructL(const TDesC8& aEncoding)
1.67 + {
1.68 + // Use decoder to get information about the outer wrapper of the passed
1.69 + // encoding.
1.70 + TASN1DecGeneric decoder(aEncoding);
1.71 + decoder.InitL();
1.72 + iClass = decoder.Class();
1.73 + iTag = decoder.Tag();
1.74 + // Set this information so that the base class knows how to write
1.75 + // DER encoding.
1.76 + SetTag(iTag, iClass);
1.77 + // Copy just the contents of the passed encoding.
1.78 + iContents = decoder.GetContentDER().AllocL();
1.79 + // Save this for base class writing functions.
1.80 + iContentsLengthDER = iContents->Length();
1.81 + // This is base class' method which initializes length of length
1.82 + // encoding for proper DER writing.
1.83 + CalculateLengthLengthDER();
1.84 + }
1.85 +
1.86 +void CASN1EncEncoding::ConstructL(const TDesC8& aEncoding, TTagType aType, TASN1Class aClass)
1.87 + {
1.88 + // Use decoder to get information about the outer wrapper of the passed
1.89 + // encoding.
1.90 + TASN1DecGeneric decoder(aEncoding);
1.91 + decoder.InitL();
1.92 + iClass = aClass;
1.93 + iTag = aType;
1.94 + // Set this information so that the base class knows how to write
1.95 + // DER encoding.
1.96 + SetTag(aType, aClass);
1.97 + // Copy just the contents of the passed encoding.
1.98 + iContents = decoder.GetContentDER().AllocL();
1.99 + // Save this for base class writing functions.
1.100 + iContentsLengthDER = iContents->Length();
1.101 + // This is base class' method which initializes length of length
1.102 + // encoding for proper DER writing.
1.103 + CalculateLengthLengthDER();
1.104 + }
1.105 +
1.106 +
1.107 +// This method is not called but is necessary because it overrides a
1.108 +// pure virtual function of the base class. The variable is properly
1.109 +// initialized in ConstructL().
1.110 +void CASN1EncEncoding::CalculateContentsLengthDER()
1.111 + {
1.112 + iContentsLengthDER = iContents->Length();
1.113 + }
1.114 +
1.115 +TBool CASN1EncEncoding::IsConstructed() const
1.116 + {
1.117 + return ETrue;
1.118 + }
1.119 +
1.120 +// When this method is called by the base class write helper, the tag
1.121 +// and length are already written.
1.122 +void CASN1EncEncoding::WriteContentsDERL(TDes8& aBuf) const
1.123 + {
1.124 + aBuf.Copy(*iContents);
1.125 + }