|
1 /* |
|
2 * Copyright (c) 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 "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: Class containing information about one public key. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <x509cert.h> |
|
22 #include "ikepublickey.h" |
|
23 |
|
24 // |
|
25 // CPublickey Class |
|
26 // |
|
27 CIkePublicKey* CIkePublicKey::NewL(const CX509Certificate& aCert) |
|
28 { |
|
29 CIkePublicKey* PubKey = new (ELeave) CIkePublicKey(); |
|
30 CleanupStack::PushL(PubKey); |
|
31 |
|
32 switch ( aCert.PublicKey().AlgorithmId() ) |
|
33 { |
|
34 case ERSA: |
|
35 PubKey->iAlgorithm = EPKIRSA; |
|
36 PubKey->iKeyData = HBufC8::NewL(aCert.PublicKey().KeyData().Length()); |
|
37 PubKey->iKeyData->Des().Copy(aCert.PublicKey().KeyData()); |
|
38 CleanupStack::Pop(PubKey); //PubKey only removed from cleanup stack |
|
39 break; |
|
40 |
|
41 case EDSA: |
|
42 PubKey->iAlgorithm = EPKIDSA; |
|
43 PubKey->iKeyData = HBufC8::NewL(aCert.PublicKey().KeyData().Length()); |
|
44 PubKey->iKeyData->Des().Copy(aCert.PublicKey().KeyData()); |
|
45 PubKey->iKeyParams = HBufC8::NewL(aCert.PublicKey().EncodedParams().Length()); |
|
46 PubKey->iKeyParams->Des().Copy(aCert.PublicKey().EncodedParams()); |
|
47 CleanupStack::Pop(PubKey); //PubKey only removed from cleanup stack |
|
48 break; |
|
49 |
|
50 default: |
|
51 CleanupStack::PopAndDestroy(PubKey); |
|
52 PubKey = NULL; |
|
53 break; |
|
54 } |
|
55 |
|
56 return PubKey; |
|
57 } |
|
58 |
|
59 |
|
60 CIkePublicKey::CIkePublicKey() |
|
61 :iAlgorithm(EPKIInvalidAlgorithm) |
|
62 { |
|
63 } |
|
64 |
|
65 |
|
66 CIkePublicKey::~CIkePublicKey() |
|
67 { |
|
68 delete iKeyParams; |
|
69 delete iKeyData; |
|
70 } |
|
71 |
|
72 |
|
73 TPKIKeyAlgorithm CIkePublicKey::Algorithm() const |
|
74 { |
|
75 return iAlgorithm; |
|
76 } |
|
77 |
|
78 |
|
79 const TDesC8& CIkePublicKey::KeyData() const |
|
80 { |
|
81 return *iKeyData; |
|
82 } |
|
83 |
|
84 |
|
85 const TDesC8& CIkePublicKey::KeyParams() const |
|
86 { |
|
87 return *iKeyParams; |
|
88 } |