|
1 /* |
|
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Implementation for class encoding printable strings in ASN1 DER |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <asn1enc.h> |
|
21 |
|
22 const TInt8 PrintableStringValid[256]= |
|
23 { |
|
24 // 0 1 2 3 4 5 6 7 8 9 a b c d e f |
|
25 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0 |
|
26 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 1 |
|
27 0,0,0,0,0,0,0,1,1,1,0,1,1,1,1,1, // 2 |
|
28 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, // 3 |
|
29 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 4 |
|
30 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, // 5 |
|
31 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 6 |
|
32 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, // 7 |
|
33 }; |
|
34 |
|
35 EXPORT_C CASN1EncPrintableString* CASN1EncPrintableString::NewLC(const TDesC8& aStr) |
|
36 { |
|
37 CASN1EncPrintableString* self = new (ELeave) CASN1EncPrintableString(); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(aStr); |
|
40 return self; |
|
41 } |
|
42 |
|
43 EXPORT_C CASN1EncPrintableString* CASN1EncPrintableString::NewL(const TDesC8& aStr) |
|
44 { |
|
45 CASN1EncPrintableString* self = NewLC(aStr); |
|
46 CleanupStack::Pop(self); |
|
47 return self; |
|
48 } |
|
49 |
|
50 EXPORT_C CASN1EncPrintableString::~CASN1EncPrintableString() |
|
51 { |
|
52 delete iContents; |
|
53 } |
|
54 |
|
55 |
|
56 CASN1EncPrintableString::CASN1EncPrintableString() |
|
57 : CASN1EncPrimitive(EASN1PrintableString) |
|
58 { |
|
59 } |
|
60 |
|
61 TInt CASN1EncPrintableString::CheckValid(const TDesC8& aString) |
|
62 { |
|
63 TInt i; |
|
64 for (i = 0; i < aString.Length(); ++i) |
|
65 { |
|
66 if ((aString[i] > 0x7F) || (PrintableStringValid[aString[i]] == 0)) |
|
67 { |
|
68 return EFalse; |
|
69 } |
|
70 } |
|
71 return ETrue; |
|
72 } |
|
73 |
|
74 void CASN1EncPrintableString::ConstructL(const TDesC8& aStr) |
|
75 { |
|
76 if (CheckValid(aStr) == EFalse) |
|
77 { |
|
78 User::Leave(KErrArgument); |
|
79 } |
|
80 iContents = aStr.AllocL(); |
|
81 CASN1EncPrimitive::ConstructL(); |
|
82 } |
|
83 |
|
84 |
|
85 void CASN1EncPrintableString::CalculateContentsLengthDER() |
|
86 { |
|
87 iContentsLengthDER = iContents->Length(); |
|
88 } |
|
89 |
|
90 |
|
91 void CASN1EncPrintableString::WriteContentsDERL(TDes8& aBuf) const |
|
92 { |
|
93 aBuf.Copy(*iContents); |
|
94 } |