|
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: JNI Layer corresponding to Signature.java |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "com_nokia_mj_impl_security_SignatureImpl.h" |
|
20 |
|
21 #include "stssignature.h" |
|
22 #include "stssignaturefactory.h" |
|
23 #include "stsconstants.h" |
|
24 |
|
25 using namespace java::satsa; |
|
26 |
|
27 |
|
28 // JNI function. |
|
29 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_security_SignatureImpl__1verify |
|
30 (JNIEnv* aJni, jclass, jint aHandle, |
|
31 jbyteArray aSignature) |
|
32 { |
|
33 int retVal = 0; |
|
34 STSSignature* signature = reinterpret_cast< STSSignature* >(aHandle); |
|
35 |
|
36 // Call Verify. |
|
37 retVal = signature->Verify(aJni,aSignature); |
|
38 |
|
39 return retVal; |
|
40 } |
|
41 |
|
42 // JNI function. |
|
43 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_security_SignatureImpl__1update |
|
44 (JNIEnv* aJni, jclass, jint aHandle, jbyteArray aData, jint aOffset, |
|
45 jint aLength) |
|
46 { |
|
47 STSSignature* signature = reinterpret_cast< STSSignature* >(aHandle); |
|
48 int err = 0; |
|
49 |
|
50 // Call Update |
|
51 err = signature->Update(aJni,aData, aOffset,aLength); |
|
52 |
|
53 return err; |
|
54 } |
|
55 |
|
56 // JNI function. |
|
57 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_security_SignatureImpl__1initVerify |
|
58 (JNIEnv* aJni, jclass, jint aHandle, jstring aKeyAlgorithm, jstring aKeyFormat, |
|
59 jbyteArray aKeyEncoded) |
|
60 { |
|
61 STSSignature* signature = reinterpret_cast< STSSignature* >(aHandle); |
|
62 int err = 0; |
|
63 |
|
64 // Call InitVerify |
|
65 err = signature->InitVerify(aJni, |
|
66 aKeyAlgorithm, |
|
67 aKeyFormat, |
|
68 aKeyEncoded); |
|
69 |
|
70 return err; |
|
71 } |
|
72 |
|
73 // JNI function. |
|
74 JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_security_SignatureImpl__1create |
|
75 (JNIEnv* aJni, |
|
76 jclass, |
|
77 jstring aAlgorithm) |
|
78 { |
|
79 |
|
80 int handle = KSTSErrNoMemory; |
|
81 int errCode = 0; |
|
82 |
|
83 STSSignature* aSignature = NULL; |
|
84 |
|
85 // Call CreateSignature. |
|
86 aSignature = STSSignatureFactory::CreateSignature(aJni, aAlgorithm, &errCode); |
|
87 |
|
88 if (aSignature == NULL) |
|
89 { |
|
90 // CreateSignature returned error. |
|
91 // Set error code to handle variable which is returned to Java |
|
92 handle = errCode; |
|
93 } |
|
94 else |
|
95 { |
|
96 // signature created successfully, return handle to new signature object |
|
97 handle = reinterpret_cast<jint>(aSignature); |
|
98 } |
|
99 |
|
100 return handle; |
|
101 } |
|
102 |
|
103 // JNI function dispose. |
|
104 JNIEXPORT void |
|
105 JNICALL Java_com_nokia_mj_impl_security_SignatureImpl__1dispose |
|
106 (JNIEnv* /*aJni*/, |
|
107 jclass, |
|
108 jint aHandle) |
|
109 { |
|
110 |
|
111 //Get the signature object from aHandle |
|
112 STSSignature* signature = reinterpret_cast< STSSignature* >(aHandle); |
|
113 |
|
114 if (signature != NULL) |
|
115 { |
|
116 // Cleanup the native handle. |
|
117 delete signature; |
|
118 signature = 0; |
|
119 } |
|
120 |
|
121 }//end dispose |
|
122 |
|
123 |
|
124 |