sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2000-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 directory string ASN1 object
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "X500dec.h"
|
sl@0
|
21 |
|
sl@0
|
22 |
/*
|
sl@0
|
23 |
|
sl@0
|
24 |
This file contains the implementation of the following ASN1 data structures:
|
sl@0
|
25 |
|
sl@0
|
26 |
DirectoryString ::= CHOICE {
|
sl@0
|
27 |
teletexString TeletexString (SIZE (1..MAX)),
|
sl@0
|
28 |
printableString PrintableString (SIZE (1..MAX)),
|
sl@0
|
29 |
universalString UniversalString (SIZE (1..MAX)),
|
sl@0
|
30 |
utf8String UTF8String (SIZE (1..MAX)),
|
sl@0
|
31 |
bmpString BMPString (SIZE(1..MAX)) }
|
sl@0
|
32 |
|
sl@0
|
33 |
*/
|
sl@0
|
34 |
|
sl@0
|
35 |
TASN1DecX500DirectoryString::TASN1DecX500DirectoryString(void):
|
sl@0
|
36 |
iMaxLength(KMaxTInt)
|
sl@0
|
37 |
{
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
HBufC* TASN1DecX500DirectoryString::DecodeDERL(const TDesC8& aSource,TInt& aPos, TInt aMaxLength)
|
sl@0
|
41 |
|
sl@0
|
42 |
{
|
sl@0
|
43 |
TPtrC8 Ptr=aSource.Right(aSource.Length()-aPos);
|
sl@0
|
44 |
TASN1DecGeneric gen(Ptr);
|
sl@0
|
45 |
gen.InitL();
|
sl@0
|
46 |
aPos+=gen.LengthDER();
|
sl@0
|
47 |
HBufC* Object=DecodeContentsL(gen, aMaxLength);
|
sl@0
|
48 |
return Object;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
HBufC* TASN1DecX500DirectoryString::DecodeDERL(const TASN1DecGeneric& aSource, TInt aMaxLength)
|
sl@0
|
52 |
|
sl@0
|
53 |
{
|
sl@0
|
54 |
return DecodeContentsL(aSource, aMaxLength);
|
sl@0
|
55 |
}
|
sl@0
|
56 |
|
sl@0
|
57 |
HBufC* TASN1DecX500DirectoryString::DecodeContentsL(const TASN1DecGeneric& aSource, TInt aMaxLength)
|
sl@0
|
58 |
{
|
sl@0
|
59 |
HBufC* res = NULL;
|
sl@0
|
60 |
switch (aSource.Tag())
|
sl@0
|
61 |
{
|
sl@0
|
62 |
case EASN1TeletexString:
|
sl@0
|
63 |
{
|
sl@0
|
64 |
TASN1DecTeletexString tStr;
|
sl@0
|
65 |
res = tStr.DecodeDERL(aSource);
|
sl@0
|
66 |
break;
|
sl@0
|
67 |
}
|
sl@0
|
68 |
case EASN1PrintableString:
|
sl@0
|
69 |
{
|
sl@0
|
70 |
TASN1DecPrintableString pStr;
|
sl@0
|
71 |
res = pStr.DecodeDERL(aSource);
|
sl@0
|
72 |
break;
|
sl@0
|
73 |
}
|
sl@0
|
74 |
case EASN1IA5String:
|
sl@0
|
75 |
{
|
sl@0
|
76 |
TASN1DecIA5String pStr;
|
sl@0
|
77 |
res = pStr.DecodeDERL(aSource);
|
sl@0
|
78 |
break;
|
sl@0
|
79 |
}
|
sl@0
|
80 |
case EASN1UTF8String:
|
sl@0
|
81 |
{
|
sl@0
|
82 |
TASN1DecUTF8String pStr;
|
sl@0
|
83 |
res = pStr.DecodeDERL(aSource);
|
sl@0
|
84 |
break;
|
sl@0
|
85 |
}
|
sl@0
|
86 |
case EASN1BMPString:
|
sl@0
|
87 |
{
|
sl@0
|
88 |
TASN1DecBMPString pStr;
|
sl@0
|
89 |
res = pStr.DecodeDERL(aSource);
|
sl@0
|
90 |
break;
|
sl@0
|
91 |
}
|
sl@0
|
92 |
default:
|
sl@0
|
93 |
{
|
sl@0
|
94 |
User::Leave(KErrNotSupported);
|
sl@0
|
95 |
break;
|
sl@0
|
96 |
}
|
sl@0
|
97 |
}
|
sl@0
|
98 |
if (res->Length() > aMaxLength)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
delete res;
|
sl@0
|
101 |
User::Leave(KErrArgument);
|
sl@0
|
102 |
}
|
sl@0
|
103 |
return res;
|
sl@0
|
104 |
}
|
sl@0
|
105 |
|
sl@0
|
106 |
void TASN1DecX500DirectoryString::SetMaxLength(TInt aLength)
|
sl@0
|
107 |
// perhaps this should have some kind of testing to make sure the current
|
sl@0
|
108 |
// contents are valid...this is not as easy as it might first appear, the
|
sl@0
|
109 |
// contents might be eight or sixteen bits.
|
sl@0
|
110 |
{
|
sl@0
|
111 |
iMaxLength=aLength;
|
sl@0
|
112 |
}
|