|
1 /* |
|
2 * Copyright (c) 2008 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: Implementation of STSCipherFactory. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "stscipherfactory.h" |
|
21 #include "stssymmetriccipher.h" |
|
22 #include "ststransformation.h" |
|
23 #include "stsrsacipher.h" |
|
24 #include "logger.h" |
|
25 |
|
26 namespace java |
|
27 { |
|
28 namespace satsa |
|
29 { |
|
30 |
|
31 //factory method which creates the cipher based on the transformation |
|
32 STSCipher* STSCipherFactory::CreateCipher(JNIEnv* aJni, |
|
33 jstring aTransformation, int* errCode) |
|
34 { |
|
35 LOG(ESATSA, EInfo, "STSCipherFactory::CreateCipher+"); |
|
36 OpenSSL_add_all_algorithms(); |
|
37 |
|
38 // Create the transformation object |
|
39 // Transformation is a form of algorithm/mode/padding or |
|
40 // algorithm |
|
41 STSTransformation* transformation = STSTransformation::Create(aJni, |
|
42 aTransformation, errCode); |
|
43 |
|
44 if (transformation == NULL) |
|
45 { |
|
46 // transformation was not created successfully and errCode is set approriately |
|
47 ELOG(ESATSA, "transformation was not created successfully"); |
|
48 return NULL; |
|
49 } |
|
50 |
|
51 // Transformation succeeded, create the cipher object. |
|
52 STSCipher* cipher = NULL; |
|
53 |
|
54 if ((transformation->Algorithm() == STSAlgorithm3DES) |
|
55 || (transformation->Algorithm() == STSAlgorithmAES) |
|
56 || (transformation->Algorithm() == STSAlgorithmRC2) |
|
57 || (transformation->Algorithm() == STSAlgorithmDES)) |
|
58 { |
|
59 // Create the native symmetric cipher |
|
60 LOG(ESATSA, EInfo, "STSCipherFactory::CreateCipher: Create the native symmetric cipher"); |
|
61 cipher = STSSymmetricCipher::Create(transformation, errCode); |
|
62 } |
|
63 else if (transformation->Algorithm() == STSAlgorithmRSA) |
|
64 { |
|
65 // Create the native RSA cipher. |
|
66 LOG(ESATSA, EInfo, "STSCipherFactory::CreateCipher: Create the native RSA cipher"); |
|
67 cipher = STSRSACipher::Create(errCode); |
|
68 } |
|
69 else |
|
70 { |
|
71 // Unsupported algorithm, return NULL. |
|
72 ELOG(ESATSA, "STSCipherFactory::CreateCipher: Unsupported algorithm, return NULL."); |
|
73 *errCode = KSTSErrNoSuchAlgorithm; |
|
74 return NULL; |
|
75 } |
|
76 |
|
77 if (cipher != NULL) |
|
78 { |
|
79 // Cipher created successfully. |
|
80 // Set the transformation that is expected in the cipher object that was created above |
|
81 LOG(ESATSA, EInfo, "STSCipherFactory::CreateCipher: Cipher created successfully."); |
|
82 cipher->SetTransformation(transformation); |
|
83 } |
|
84 |
|
85 LOG(ESATSA, EInfo, "STSCipherFactory::CreateCipher: return cipher"); |
|
86 // return the cipher object. |
|
87 return cipher; |
|
88 } |
|
89 } // namespace satsa |
|
90 } // namespace java |
|
91 |
|
92 |