First public contribution.
2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Implementation for class encoding TInt in ASN1 DER
22 EXPORT_C CASN1EncInt* CASN1EncInt::NewLC(const TInt aInt)
24 CASN1EncInt* self = new (ELeave) CASN1EncInt(aInt);
25 CleanupStack::PushL(self);
30 EXPORT_C CASN1EncInt* CASN1EncInt::NewL(const TInt aInt)
32 CASN1EncInt* self = NewLC(aInt);
33 CleanupStack::Pop(self);
37 CASN1EncInt::CASN1EncInt(const TInt aInt)
38 : CASN1EncPrimitive(EASN1Integer), iInt(aInt)
42 void CASN1EncInt::CalculateContentsLengthDER()
44 iContentsLengthDER = 1;
46 // Flip bits in -ve numbers
47 TUint working = iInt < 0 ? ~iInt : iInt;
55 // If most sig non-zero byte had a 1 top bit, we'll need the next byte too
56 // (applies to both +ve and -ve cases)
64 void CASN1EncInt::WriteContentsDERL(TDes8& aBuf) const
66 // Unsigned, so operator>>= works sensibly
68 TUint position = iContentsLengthDER;
71 // Cast takes least sig 8 bits
72 aBuf[--position] = STATIC_CAST(TUint8, working);