Update contrib.
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 the class encoding Big Integers in ASN1 DER
25 EXPORT_C CASN1EncBigInt* CASN1EncBigInt::NewLC(const TInteger& aInteger)
27 CASN1EncBigInt* self = new (ELeave) CASN1EncBigInt();
28 CleanupStack::PushL(self);
29 self->ConstructL(aInteger);
33 EXPORT_C CASN1EncBigInt* CASN1EncBigInt::NewL(const TInteger& aInteger)
35 CASN1EncBigInt* self = NewLC(aInteger);
36 CleanupStack::Pop(self);
41 EXPORT_C CASN1EncBigInt::~CASN1EncBigInt()
47 CASN1EncBigInt::CASN1EncBigInt()
48 : CASN1EncPrimitive(EASN1Integer)
52 void CASN1EncBigInt::ConstructL(const TInteger& aInteger)
54 iContents = aInteger.BufferLC();
56 CleanupStack::Pop(); // We take ownership of the contents
58 // May wish to skip leading byte(s) if they're unnecessary - use
59 // iWriteContents to point to the minimal part of Contents, that we'll actually use.
60 TInt last = iContents->Length() - 1;
62 // if (aInteger >= 0) // Only signed integers now...
65 && (*iContents)[first] == 0
66 && !((*iContents)[first + 1] & 0x80))
74 && (*iContents)[first] == 0xFF
75 && (*iContents)[first + 1] & 0x80)
81 //to encode positive integers correctly add a leading zero byte
82 //if the first bit is set DEF038956
83 if (iContents->Length() != 0)
85 if ((*iContents)[first] & 0x80)
87 _LIT8(KPadZero, "\0");
88 TPtr8 ptr = iContents->Des();
89 //check if the buffer does not have enough space to insert a byte
90 if (ptr.Length() == ptr.MaxLength())
92 iContents = iContents->ReAllocL(iContents->Length() + 1);
93 TPtr8 reallocptr = iContents->Des();
94 reallocptr.Insert(0, KPadZero);
97 ptr.Insert(0, KPadZero);
102 iWriteContents.Set(iContents->Mid(first));
104 CASN1EncPrimitive::ConstructL();
108 void CASN1EncBigInt::CalculateContentsLengthDER()
110 iContentsLengthDER = iWriteContents.Length();
114 void CASN1EncBigInt::WriteContentsDERL(TDes8& aBuf) const
116 aBuf.Copy(iWriteContents);