Update contrib.
2 * Copyright (c) 1998-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 * This file contains the object implementing the Bitstring ASN1 object.
16 * There is no handling for constructed form of Bitstring right now.
23 EXPORT_C TASN1DecBitString::TASN1DecBitString(void)
27 EXPORT_C HBufC8* TASN1DecBitString::DecodeDERL(const TDesC8& /*aSource*/,TInt& /*aPos*/)
29 User::Leave(KErrNotSupported);
33 EXPORT_C HBufC8* TASN1DecBitString::DecodeDERL(const TASN1DecGeneric& /*aSource*/)
35 User::Leave(KErrNotSupported);
39 EXPORT_C HBufC8* TASN1DecBitString::ExtractOctetStringL(const TDesC8& aSource,TInt& aPos)
41 TASN1DecGeneric gen(aSource.Right(aSource.Length() - aPos));
43 HBufC8* res = ExtractOctetStringL(gen);
44 aPos+=gen.LengthDER();
48 EXPORT_C HBufC8* TASN1DecBitString::ExtractOctetStringL(const TASN1DecGeneric& aSource)
50 TPtrC8 encoding = aSource.GetContentDER();
52 // Special case. The empty bit string. (No padding length octet)
53 if (encoding.Length() == 0 )
55 return encoding.AllocL();
58 // Length must either be 0 for the empty string or >= 2 because
59 // of the padding length octet.
60 if (encoding.Length() == 1)
62 User::Leave(KErrArgument);
65 TUint8 paddingLength = encoding[0];
66 if (paddingLength > 7)
68 User::Leave(KErrArgument);
70 TPtrC8 pEncoding = encoding.Right(encoding.Length()-1);
71 HBufC8* octetStr = pEncoding.AllocL();
72 TPtr8 pEncKey = octetStr->Des();
74 //stop stupid compiler warning
75 TUint8 mask =(TUint8)(255 << paddingLength);
76 //stop stupid compiler warning
77 pEncKey[pEncKey.Length()-1] = (TUint8) ((pEncKey[pEncKey.Length()-1]) & mask);