1 | package org.expeditee.settings.identity.secrets;
|
---|
2 |
|
---|
3 | import java.util.Arrays;
|
---|
4 | import java.util.List;
|
---|
5 | import java.util.function.Predicate;
|
---|
6 | import java.util.stream.Collectors;
|
---|
7 | import java.util.stream.Stream;
|
---|
8 |
|
---|
9 | import org.expeditee.gui.Frame;
|
---|
10 | import org.expeditee.items.Text;
|
---|
11 | import org.expeditee.setting.ArraySetting;
|
---|
12 | import org.expeditee.setting.TextSetting;
|
---|
13 |
|
---|
14 | public class KeyList {
|
---|
15 |
|
---|
16 | public static final TextSetting PersonalKey = new TextSetting("The AES key used to secure your profile frame - do not share with anyone!", "PersonalKey") {
|
---|
17 | @Override
|
---|
18 | public Text generateText() {
|
---|
19 | Text t = new Text("PersonalKey");
|
---|
20 | return t;
|
---|
21 | }
|
---|
22 | };
|
---|
23 |
|
---|
24 | public static final TextSetting PrivateKey = new TextSetting("The RSA key used to decrypt things encrypted with your RSA public key - do not share with anyone!", "PrivateKey") {
|
---|
25 | @Override
|
---|
26 | public Text generateText() {
|
---|
27 | Text t = new Text("PrivateKey");
|
---|
28 | return t;
|
---|
29 | }
|
---|
30 | };
|
---|
31 |
|
---|
32 | public static final ArraySetting<Text> UserLabels = new ArraySetting<Text>("The labels (and their associated keys) that you have either created or recieved.",
|
---|
33 | "UserLabels", new Text[] { }) {
|
---|
34 |
|
---|
35 | @Override
|
---|
36 | public boolean setSetting(Text text) {
|
---|
37 | Frame child = text.getChild();
|
---|
38 | if (child == null) {
|
---|
39 | return false;
|
---|
40 | }
|
---|
41 |
|
---|
42 | Predicate<Text> hasNoData = t -> {
|
---|
43 | List<String> data = t.getData();
|
---|
44 | return data == null || data.isEmpty();
|
---|
45 | };
|
---|
46 | List<Text> textItems = child.getBodyTextItems(false);
|
---|
47 | textItems.removeIf(hasNoData);
|
---|
48 | _value = textItems.toArray(new Text[] {});
|
---|
49 |
|
---|
50 | return true;
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override
|
---|
54 | public Text generateRepresentation(String label, String frameset) {
|
---|
55 | Text t = new Text(label);
|
---|
56 |
|
---|
57 | createChildFrame(frameset, t, "My Labels");
|
---|
58 |
|
---|
59 | return t;
|
---|
60 | }
|
---|
61 | };
|
---|
62 |
|
---|
63 | public static List<String> getLabelsNameOnly() {
|
---|
64 | Text[] allLabels = UserLabels.get();
|
---|
65 | Stream<String> allLabelsNames = Arrays.asList(allLabels).stream().map(label -> label.getText());
|
---|
66 | return allLabelsNames.collect(Collectors.toList());
|
---|
67 | }
|
---|
68 |
|
---|
69 | public static Text getByName(String labelName) {
|
---|
70 | Text[] allLabels = UserLabels.get();
|
---|
71 | for (Text label: allLabels) {
|
---|
72 | if (label.getText().equals(labelName)) {
|
---|
73 | return label;
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | return null;
|
---|
78 | }
|
---|
79 | }
|
---|