|
1 /* |
|
2 * Copyright (c) 2001-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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "securitydefs.h" |
|
20 |
|
21 //////////////////////////////////////////////////////////////////////////////// |
|
22 // TKeyUsagePKCS15 & TKeyUsageX509 |
|
23 //////////////////////////////////////////////////////////////////////////////// |
|
24 |
|
25 // x509 PKCS15 Public PKCS15 Private |
|
26 |
|
27 // DataEncipherment Encrypt Decrypt |
|
28 // DigitalSignature, keyCertSign, cRLSign Verify Sign |
|
29 // DigitalSignature, keyCertSign, cRLSign VerifyRecover SignRecover |
|
30 // KeyAgreement Derive Derive |
|
31 // KeyEncipherment Wrap Unwrap |
|
32 // NonRepudiation NonRepudiation NonRepudiation |
|
33 |
|
34 EXPORT_C TKeyUsagePKCS15 KeyUsageX509ToPKCS15Private(TKeyUsageX509 aUsage) |
|
35 { |
|
36 TKeyUsagePKCS15 result = EPKCS15UsageNone; |
|
37 |
|
38 if (EX509UsageAll == aUsage) |
|
39 { |
|
40 result = EPKCS15UsageAll; |
|
41 } |
|
42 else |
|
43 { |
|
44 if (aUsage & EX509UsageDataEncipherment) |
|
45 { |
|
46 result |= EPKCS15UsageDecrypt; |
|
47 } |
|
48 if (aUsage & (EX509UsageDigitalSignature | EX509UsageKeyCertSign | EX509UsageCRLSign)) |
|
49 { |
|
50 result |= EPKCS15UsageSign | EPKCS15UsageSignRecover; |
|
51 } |
|
52 if (aUsage & EX509UsageKeyAgreement) |
|
53 { |
|
54 result |= EPKCS15UsageDerive; |
|
55 } |
|
56 if (aUsage & EX509UsageKeyEncipherment) |
|
57 { |
|
58 result |= EPKCS15UsageUnwrap; |
|
59 } |
|
60 if (aUsage & EX509UsageNonRepudiation) |
|
61 {// This shouldn't really happen, ENonRepudiation should be sole usage |
|
62 result |= EPKCS15UsageNonRepudiation; |
|
63 } |
|
64 } |
|
65 |
|
66 return result; |
|
67 } |
|
68 |
|
69 EXPORT_C TKeyUsagePKCS15 KeyUsageX509ToPKCS15Public(TKeyUsageX509 aUsage) |
|
70 { |
|
71 TKeyUsagePKCS15 result = EPKCS15UsageNone; |
|
72 |
|
73 if (EX509UsageAll == aUsage) |
|
74 { |
|
75 result = EPKCS15UsageAll; |
|
76 } |
|
77 else |
|
78 { |
|
79 if (aUsage & EX509UsageDataEncipherment) |
|
80 { |
|
81 result |= EPKCS15UsageEncrypt; |
|
82 } |
|
83 if (aUsage & (EX509UsageDigitalSignature | EX509UsageKeyCertSign | EX509UsageCRLSign)) |
|
84 { |
|
85 result |= EPKCS15UsageVerify | EPKCS15UsageVerifyRecover; |
|
86 } |
|
87 if (aUsage & EX509UsageKeyAgreement) |
|
88 { |
|
89 result |= EPKCS15UsageDerive; |
|
90 } |
|
91 if (aUsage & EX509UsageKeyEncipherment) |
|
92 { |
|
93 result |= EPKCS15UsageWrap; |
|
94 } |
|
95 if (aUsage & EX509UsageNonRepudiation) |
|
96 {// This shouldn't really happen, ENonRepudiation should be sole usage |
|
97 result |= EPKCS15UsageNonRepudiation; |
|
98 } |
|
99 } |
|
100 |
|
101 return result; |
|
102 } |
|
103 |
|
104 EXPORT_C TKeyUsageX509 KeyUsagePKCS15ToX509(TKeyUsagePKCS15 aUsage) |
|
105 { |
|
106 TKeyUsageX509 result = EX509UsageNone; |
|
107 |
|
108 if (EPKCS15UsageAll == aUsage) |
|
109 { |
|
110 result = EX509UsageAll; |
|
111 } |
|
112 else |
|
113 { |
|
114 if (aUsage & (EPKCS15UsageEncrypt | EPKCS15UsageDecrypt)) |
|
115 { |
|
116 result |= EX509UsageDataEncipherment; |
|
117 } |
|
118 if (aUsage & (EPKCS15UsageVerify | EPKCS15UsageSign | EPKCS15UsageVerifyRecover | EPKCS15UsageSignRecover)) |
|
119 { |
|
120 result |= EX509UsageDigitalSignature | EX509UsageKeyCertSign | EX509UsageCRLSign; |
|
121 } |
|
122 if (aUsage & EPKCS15UsageDerive) |
|
123 { |
|
124 result |= EX509UsageKeyAgreement; |
|
125 } |
|
126 if (aUsage & (EPKCS15UsageWrap | EPKCS15UsageUnwrap)) |
|
127 { |
|
128 result |= EX509UsageKeyEncipherment; |
|
129 } |
|
130 if (aUsage & EPKCS15UsageNonRepudiation) |
|
131 { |
|
132 result |= EX509UsageNonRepudiation; |
|
133 } |
|
134 } |
|
135 |
|
136 return result; |
|
137 } |