1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/asn1/base128enc.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,64 @@
1.4 +/*
1.5 +* Copyright (c) 2001-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 +* Implementation for TASN1EncBase128 class.
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +#include "base128enc.h"
1.24 +
1.25 +
1.26 +TASN1EncBase128DER::TASN1EncBase128DER(TUint aInt) : iInt(aInt), iLengthDER(0)
1.27 + {
1.28 + CalculateLengthDER();
1.29 + }
1.30 +
1.31 +
1.32 +TUint TASN1EncBase128DER::LengthDER() const
1.33 + {
1.34 + return iLengthDER;
1.35 + }
1.36 +
1.37 +
1.38 +void TASN1EncBase128DER::CalculateLengthDER()
1.39 + {
1.40 + iLengthDER = 1;
1.41 + TUint working = iInt;
1.42 + while (working >>= 7)
1.43 + {
1.44 + ++iLengthDER;
1.45 + }
1.46 + }
1.47 +
1.48 +
1.49 +void TASN1EncBase128DER::WriteDERL(TDes8& aBuf, TUint& aPos) const
1.50 + {
1.51 + __ASSERT_DEBUG(aBuf.Length() - aPos >= STATIC_CAST(TUint8, iLengthDER),
1.52 + User::Leave(KErrBadDescriptor));
1.53 +
1.54 + TInt last = aPos + iLengthDER - 1;
1.55 + TUint working = iInt;
1.56 + for (TUint cursor = last; cursor >= aPos; --cursor)
1.57 + {
1.58 + // Cast takes least significant 8 bits only (actually, we only need 7)
1.59 + aBuf[cursor] = STATIC_CAST(TUint8, working);
1.60 + aBuf[cursor] |= 0x80; // Top bit always set to 1...
1.61 + working >>= 7;
1.62 + }
1.63 + // ...except top bit on last byte is 0
1.64 + aBuf[last] &= 0x7F;
1.65 +
1.66 + aPos += iLengthDER;
1.67 + }