Skip to content

Commit 64da90b

Browse files
Igor Fernandesigorrfc
authored andcommitted
Update RNSensitiveInfoModule
Changes: - changed the getAllItems method error handling to log the error stack trace instead of the `getCause().getMessage()` chain. This was needed because some exceptions caused at decrypt function doesn't have an explicit cause and because of that, the getCause() at the getAllItems' catch was returning null and trying to call the getMessage(). Which is not possible, of course. - added a new argument validation at decrypt method, checking if the encrypted attribute is null;
1 parent 55856ba commit 64da90b

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

android/src/main/java/br/com/classapp/RNSensitiveInfo/RNSensitiveInfoModule.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public RNSensitiveInfoModule(ReactApplicationContext reactContext) {
5555
try {
5656
initKeyStore(reactContext);
5757
} catch (Exception e) {
58-
Log.d("RNSensitiveInfo", e.getCause().getMessage());
58+
Log.d("RNSensitiveInfo", Log.getStackTraceString(e));
5959
}
6060
}
6161

@@ -74,7 +74,7 @@ public void getItem(String key, ReadableMap options, Promise pm) {
7474
try {
7575
value = decrypt(value);
7676
} catch (Exception e) {
77-
Log.d("RNSensitiveInfo", e.getCause().getMessage());
77+
Log.d("RNSensitiveInfo", Log.getStackTraceString(e));
7878
}
7979
}
8080

@@ -90,7 +90,7 @@ public void setItem(String key, String value, ReadableMap options, Promise pm) {
9090
putExtra(key, value, prefs(name));
9191
pm.resolve(null);
9292
} catch (Exception e) {
93-
Log.d("RNSensitiveInfo", e.getCause().getMessage());
93+
Log.d("RNSensitiveInfo", Log.getStackTraceString(e));
9494
pm.reject(e);
9595
}
9696
}
@@ -122,7 +122,7 @@ public void getAllItems(ReadableMap options, Promise pm) {
122122
try {
123123
value = decrypt(value);
124124
} catch (Exception e) {
125-
Log.d("RNSensitiveInfo", e.getCause().getMessage());
125+
Log.d("RNSensitiveInfo", Log.getStackTraceString(e));
126126
}
127127
resultData.putString(entry.getKey(), value);
128128
}
@@ -259,7 +259,13 @@ public String encrypt(String input) throws Exception {
259259

260260

261261
public String decrypt(String encrypted) throws Exception {
262+
if (encrypted == null) {
263+
Exception cause = new RuntimeException("Invalid argument at decrypt function");
264+
throw new RuntimeException("encrypted argument can't be null", cause);
265+
}
266+
262267
Cipher c;
268+
263269
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
264270
c = Cipher.getInstance(AES_GCM);
265271
c.init(Cipher.DECRYPT_MODE, secretKey, new GCMParameterSpec(128, FIXED_IV));

0 commit comments

Comments
 (0)