/
ValidateUtils.java
64 lines (50 loc) · 2.17 KB
/
ValidateUtils.java
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
56
57
58
59
60
61
62
63
64
package co.infinum.goldfinger;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
class ValidateUtils {
private ValidateUtils() {
}
/**
* Return list of cipher params errors. If no errors detected, list will be empty.
*/
@NonNull
static List<String> validateCipherParams(@NonNull Mode mode, @Nullable String key, @Nullable String value) {
List<String> errors = new ArrayList<>();
if (mode != Mode.AUTHENTICATION) {
if (StringUtils.isBlankOrNull(key)) {
errors.add("Key is required if encryption or decryption is used!");
}
if (StringUtils.isBlankOrNull(value)) {
errors.add("Value is required if encryption or decryption is used!");
}
}
return errors;
}
/**
* Return list of prompt params errors. If no errors detected, list will be empty.
*/
@NonNull
static List<String> validatePromptParams(@NonNull Mode mode, @NonNull Goldfinger.PromptParams params) {
List<String> errors = new ArrayList<>();
if (!(params.dialogOwner() instanceof Fragment) && !(params.dialogOwner() instanceof FragmentActivity)) {
errors.add("DialogOwner must be of instance Fragment or FragmentActivity");
}
if (StringUtils.isBlankOrNull(params.title())) {
errors.add("Title is required!");
}
if (params.deviceCredentialsAllowed() && !StringUtils.isBlankOrNull(params.negativeButtonText())) {
errors.add("It is not possible to set NegativeButtonText while using BiometricManager.Authenticators.DEVICE_CREDENTIAL");
}
if (!params.deviceCredentialsAllowed() && StringUtils.isBlankOrNull(params.negativeButtonText())) {
errors.add("NegativeButtonText is required!");
}
if (params.deviceCredentialsAllowed() && mode != Mode.AUTHENTICATION) {
errors.add("DeviceCredentials are allowed only for Goldfinger#authenticate method.");
}
return errors;
}
}