Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | package org.mozilla.gecko; |
michael@0 | 6 | |
michael@0 | 7 | import org.mozilla.gecko.mozglue.GeckoLoader; |
michael@0 | 8 | |
michael@0 | 9 | import android.content.Context; |
michael@0 | 10 | import org.mozilla.gecko.mozglue.RobocopTarget; |
michael@0 | 11 | |
michael@0 | 12 | public class NSSBridge { |
michael@0 | 13 | private static final String LOGTAG = "NSSBridge"; |
michael@0 | 14 | |
michael@0 | 15 | private static native String nativeEncrypt(String aDb, String aValue); |
michael@0 | 16 | private static native String nativeDecrypt(String aDb, String aValue); |
michael@0 | 17 | |
michael@0 | 18 | @RobocopTarget |
michael@0 | 19 | static public String encrypt(Context context, String aValue) |
michael@0 | 20 | throws Exception { |
michael@0 | 21 | String resourcePath = context.getPackageResourcePath(); |
michael@0 | 22 | GeckoLoader.loadNSSLibs(context, resourcePath); |
michael@0 | 23 | |
michael@0 | 24 | String path = GeckoProfile.get(context).getDir().toString(); |
michael@0 | 25 | return nativeEncrypt(path, aValue); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | @RobocopTarget |
michael@0 | 29 | static public String encrypt(Context context, String profilePath, String aValue) |
michael@0 | 30 | throws Exception { |
michael@0 | 31 | String resourcePath = context.getPackageResourcePath(); |
michael@0 | 32 | GeckoLoader.loadNSSLibs(context, resourcePath); |
michael@0 | 33 | |
michael@0 | 34 | return nativeEncrypt(profilePath, aValue); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | @RobocopTarget |
michael@0 | 38 | static public String decrypt(Context context, String aValue) |
michael@0 | 39 | throws Exception { |
michael@0 | 40 | String resourcePath = context.getPackageResourcePath(); |
michael@0 | 41 | GeckoLoader.loadNSSLibs(context, resourcePath); |
michael@0 | 42 | |
michael@0 | 43 | String path = GeckoProfile.get(context).getDir().toString(); |
michael@0 | 44 | return nativeDecrypt(path, aValue); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | @RobocopTarget |
michael@0 | 48 | static public String decrypt(Context context, String profilePath, String aValue) |
michael@0 | 49 | throws Exception { |
michael@0 | 50 | String resourcePath = context.getPackageResourcePath(); |
michael@0 | 51 | GeckoLoader.loadNSSLibs(context, resourcePath); |
michael@0 | 52 | |
michael@0 | 53 | return nativeDecrypt(profilePath, aValue); |
michael@0 | 54 | } |
michael@0 | 55 | } |