os/security/cryptoservices/certificateandkeymgmt/asn1/integerdec.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/asn1/integerdec.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,90 @@
     1.4 +/*
     1.5 +* Copyright (c) 1998-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 +* This file contains the implementation of the ASN1 integer class.
    1.19 +* As noted in Notes.txt there are two approaches to the storage of data by
    1.20 +* this class, it can either hold a copy of the data or a pointer to something
    1.21 +* else which holds a copy of the data.
    1.22 +* The object contained within this file encapsulates the ASN1 integer object
    1.23 +* as described in X208 section 14 and the encoding described in X209 section
    1.24 +* 8. 
    1.25 +*
    1.26 +*/
    1.27 +
    1.28 +
    1.29 +#include "asn1dec.h"
    1.30 +#include <bigint.h>
    1.31 +
    1.32 +EXPORT_C TASN1DecInteger::TASN1DecInteger()
    1.33 +
    1.34 +	{
    1.35 +	}
    1.36 +
    1.37 +EXPORT_C TInt TASN1DecInteger::DecodeDERShortL(const TDesC8& aSource,TInt& aPos)
    1.38 +	{
    1.39 +	TPtrC8 Source=aSource.Mid(aPos);
    1.40 +	TASN1DecGeneric gen(Source);
    1.41 +	gen.InitL();
    1.42 +	TInt res = DecodeDERShortL(gen);
    1.43 +	aPos+=gen.LengthDER();
    1.44 +	return res;
    1.45 +	}
    1.46 +
    1.47 +EXPORT_C TInt TASN1DecInteger::DecodeDERShortL(const TASN1DecGeneric& aSource)
    1.48 +	{
    1.49 +	TInt res = 0;
    1.50 +	TPtrC8 ptr(aSource.GetContentDER());
    1.51 +	//stop stupid compiler warning
    1.52 +	TUint length = (TUint)(ptr.Length());
    1.53 +	if (length == 0) // DEF055722 
    1.54 +		{
    1.55 +		User::Leave(KErrArgument);
    1.56 +		}
    1.57 +	if (length > sizeof(TInt))
    1.58 +		{
    1.59 +		User::Leave(KErrTooBig);
    1.60 +		}
    1.61 +	TInt8 i;
    1.62 +	if (ptr[0]&128)
    1.63 +		{
    1.64 +		res = -1;
    1.65 +		}
    1.66 +	for (i=0;i<ptr.Length();i++)
    1.67 +		{
    1.68 +		res<<=8;
    1.69 +		res+=ptr[i];
    1.70 +		}
    1.71 +	return res;
    1.72 +	}
    1.73 +
    1.74 +EXPORT_C RInteger TASN1DecInteger::DecodeDERLongL(const TDesC8& aSource,TInt& aPos)
    1.75 +	{
    1.76 +	TPtrC8 Source=aSource.Right(aSource.Length() - aPos);
    1.77 +	TASN1DecGeneric gen(Source);
    1.78 +	gen.InitL();
    1.79 +	RInteger res = DecodeDERLongL(gen);
    1.80 +	aPos+=gen.LengthDER();
    1.81 +	return res;
    1.82 +	}
    1.83 +
    1.84 +EXPORT_C RInteger TASN1DecInteger::DecodeDERLongL(const TASN1DecGeneric& aSource)
    1.85 +	{
    1.86 +	const TDesC8& data = aSource.GetContentDER();
    1.87 +//	JCS 14/03/2003: Changed call to NewL from NewSignedL() because current
    1.88 +//	problem in RInteger for signed code means this sometimes returns incorrect
    1.89 +//	results causing failure in certstore testcode.  However, making this change
    1.90 +//	does cause problems in TASN1 now (posted defect DEF021796).
    1.91 +	RInteger res = RInteger::NewL(data);//aSource.GetContentDER());
    1.92 +	return (res);
    1.93 +	}