sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* This file contains the implementation of the ASN1 integer class.
|
sl@0
|
16 |
* As noted in Notes.txt there are two approaches to the storage of data by
|
sl@0
|
17 |
* this class, it can either hold a copy of the data or a pointer to something
|
sl@0
|
18 |
* else which holds a copy of the data.
|
sl@0
|
19 |
* The object contained within this file encapsulates the ASN1 integer object
|
sl@0
|
20 |
* as described in X208 section 14 and the encoding described in X209 section
|
sl@0
|
21 |
* 8.
|
sl@0
|
22 |
*
|
sl@0
|
23 |
*/
|
sl@0
|
24 |
|
sl@0
|
25 |
|
sl@0
|
26 |
#include "asn1dec.h"
|
sl@0
|
27 |
#include <bigint.h>
|
sl@0
|
28 |
|
sl@0
|
29 |
EXPORT_C TASN1DecInteger::TASN1DecInteger()
|
sl@0
|
30 |
|
sl@0
|
31 |
{
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
EXPORT_C TInt TASN1DecInteger::DecodeDERShortL(const TDesC8& aSource,TInt& aPos)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
TPtrC8 Source=aSource.Mid(aPos);
|
sl@0
|
37 |
TASN1DecGeneric gen(Source);
|
sl@0
|
38 |
gen.InitL();
|
sl@0
|
39 |
TInt res = DecodeDERShortL(gen);
|
sl@0
|
40 |
aPos+=gen.LengthDER();
|
sl@0
|
41 |
return res;
|
sl@0
|
42 |
}
|
sl@0
|
43 |
|
sl@0
|
44 |
EXPORT_C TInt TASN1DecInteger::DecodeDERShortL(const TASN1DecGeneric& aSource)
|
sl@0
|
45 |
{
|
sl@0
|
46 |
TInt res = 0;
|
sl@0
|
47 |
TPtrC8 ptr(aSource.GetContentDER());
|
sl@0
|
48 |
//stop stupid compiler warning
|
sl@0
|
49 |
TUint length = (TUint)(ptr.Length());
|
sl@0
|
50 |
if (length == 0) // DEF055722
|
sl@0
|
51 |
{
|
sl@0
|
52 |
User::Leave(KErrArgument);
|
sl@0
|
53 |
}
|
sl@0
|
54 |
if (length > sizeof(TInt))
|
sl@0
|
55 |
{
|
sl@0
|
56 |
User::Leave(KErrTooBig);
|
sl@0
|
57 |
}
|
sl@0
|
58 |
TInt8 i;
|
sl@0
|
59 |
if (ptr[0]&128)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
res = -1;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
for (i=0;i<ptr.Length();i++)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
res<<=8;
|
sl@0
|
66 |
res+=ptr[i];
|
sl@0
|
67 |
}
|
sl@0
|
68 |
return res;
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
EXPORT_C RInteger TASN1DecInteger::DecodeDERLongL(const TDesC8& aSource,TInt& aPos)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
TPtrC8 Source=aSource.Right(aSource.Length() - aPos);
|
sl@0
|
74 |
TASN1DecGeneric gen(Source);
|
sl@0
|
75 |
gen.InitL();
|
sl@0
|
76 |
RInteger res = DecodeDERLongL(gen);
|
sl@0
|
77 |
aPos+=gen.LengthDER();
|
sl@0
|
78 |
return res;
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
EXPORT_C RInteger TASN1DecInteger::DecodeDERLongL(const TASN1DecGeneric& aSource)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
const TDesC8& data = aSource.GetContentDER();
|
sl@0
|
84 |
// JCS 14/03/2003: Changed call to NewL from NewSignedL() because current
|
sl@0
|
85 |
// problem in RInteger for signed code means this sometimes returns incorrect
|
sl@0
|
86 |
// results causing failure in certstore testcode. However, making this change
|
sl@0
|
87 |
// does cause problems in TASN1 now (posted defect DEF021796).
|
sl@0
|
88 |
RInteger res = RInteger::NewL(data);//aSource.GetContentDER());
|
sl@0
|
89 |
return (res);
|
sl@0
|
90 |
}
|