summaryrefslogtreecommitdiffstats
path: root/mobile/android/geckoview/src/main/java/org/mozilla/gecko/NSSBridge.java
blob: 8d525b0ba6631b9de1e0c995e7b35869c8b631df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.gecko;

import org.mozilla.gecko.mozglue.GeckoLoader;

import android.content.Context;
import org.mozilla.gecko.annotation.RobocopTarget;

public class NSSBridge {
    private static final String LOGTAG = "NSSBridge";

    private static native String nativeEncrypt(String aDb, String aValue);
    private static native String nativeDecrypt(String aDb, String aValue);

    @RobocopTarget
    static public String encrypt(Context context, String aValue)
      throws Exception {
        String resourcePath = context.getPackageResourcePath();
        GeckoLoader.loadNSSLibs(context, resourcePath);

        String path = GeckoProfile.get(context).getDir().toString();
        return nativeEncrypt(path, aValue);
    }

    @RobocopTarget
    static public String encrypt(Context context, String profilePath, String aValue)
      throws Exception {
        String resourcePath = context.getPackageResourcePath();
        GeckoLoader.loadNSSLibs(context, resourcePath);

        return nativeEncrypt(profilePath, aValue);
    }

    @RobocopTarget
    static public String decrypt(Context context, String aValue)
      throws Exception {
        String resourcePath = context.getPackageResourcePath();
        GeckoLoader.loadNSSLibs(context, resourcePath);

        String path = GeckoProfile.get(context).getDir().toString();
        return nativeDecrypt(path, aValue);
    }

    @RobocopTarget
    static public String decrypt(Context context, String profilePath, String aValue)
      throws Exception {
        String resourcePath = context.getPackageResourcePath();
        GeckoLoader.loadNSSLibs(context, resourcePath);

        return nativeDecrypt(profilePath, aValue);
    }
}