|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file dhparamreader.cpp |
|
18 @internalTechnology |
|
19 */ |
|
20 #include "dhparamreader.h" |
|
21 |
|
22 #include <f32file.h> |
|
23 #include <asn1dec.h> |
|
24 |
|
25 void CDHParamReader::DecodeDERL(const TDesC& aDerFile, |
|
26 RInteger& aPrimeOut, RInteger& aGeneratorOut) |
|
27 { |
|
28 RFs fs; |
|
29 User::LeaveIfError(fs.Connect()); |
|
30 CleanupClosePushL(fs); |
|
31 |
|
32 RFile file; |
|
33 User::LeaveIfError(file.Open(fs, aDerFile, EFileRead)); |
|
34 CleanupClosePushL(file); |
|
35 |
|
36 TInt fileSize(0); |
|
37 User::LeaveIfError(file.Size(fileSize)); |
|
38 |
|
39 HBufC8* derData = HBufC8::NewLC(fileSize); |
|
40 TPtr8 derPtr = derData->Des(); |
|
41 User::LeaveIfError(file.Read(derPtr)); |
|
42 |
|
43 // we know this should just be an ASN.1 sequence, consisting of two integers.... |
|
44 TASN1DecGeneric genDec(*derData); |
|
45 genDec.InitL(); |
|
46 |
|
47 if (genDec.Tag() != EASN1Sequence) |
|
48 { |
|
49 // not a sequence... |
|
50 User::Leave(KErrNotSupported); |
|
51 } |
|
52 |
|
53 TASN1DecSequence seq; |
|
54 CArrayPtrFlat<TASN1DecGeneric>* ints = seq.DecodeDERLC(genDec); |
|
55 |
|
56 // validate the sequence data |
|
57 if (ints->Count() != 2 || |
|
58 ints->At(0)->Tag() != EASN1Integer || |
|
59 ints->At(1)->Tag() != EASN1Integer) |
|
60 { |
|
61 // This isn't a DH parameter file we can recognise... |
|
62 User::Leave(KErrNotSupported); |
|
63 } |
|
64 |
|
65 // Read the integers from the sequence.... |
|
66 TASN1DecInteger decInt; |
|
67 aPrimeOut = decInt.DecodeDERLongL(*ints->At(0)); |
|
68 aGeneratorOut = decInt.DecodeDERLongL(*ints->At(1)); |
|
69 |
|
70 CleanupStack::PopAndDestroy(4, &fs); // file, derData, ints |
|
71 } |