source: trunk/src/org/expeditee/encryption/items/surrogates/Label.java@ 1415

Last change on this file since 1415 was 1415, checked in by bln4, 5 years ago

Renamed Frame.getItems() to Frame.getSortedItems() to better represent its functionality.

-> org.apollo.ApolloGestureActions
-> org.apollo.ApolloSystem
-> org.expeditee.actions.Actions
-> org.expeditee.actions.Debug
-> org.expeditee.actions.ExploratorySearchActions
-> org.expeditee.actions.JfxBrowserActions
-> org.expeditee.actions.Misc
-> org.expeditee.actions.Navigation
-> org.expeditee.actions.ScriptBase
-> org.expeditee.actions.Simple
-> org.expeditee.agents.ComputeTree
-> org.expeditee.agents.CopyTree
-> org.expeditee.agents.DisplayComet
-> org.expeditee.agents.DisplayTree
-> org.expeditee.agents.DisplayTreeLeaves
-> org.expeditee.agents.GraphFramesetLinks
-> org.expeditee.agents.TreeProcessor
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gui.DisplayController
-> org.expeditee.gui.FrameCreator
-> org.expeditee.gui.FrameIO
-> org.expeditee.io.DefaultTreeWriter
-> org.expeditee.io.JavaWriter
-> org.expeditee.io.PDF2Writer
-> org.expeditee.io.TXTWriter
-> org.expeditee.io.WebParser
-> org.expeditee.io.flowlayout.XGroupItem
-> org.expeditee.items.Dot
-> org.expeditee.items.Item
-> org.expeditee.items.ItemUtils
-> org.expeditee.network.FrameShare
-> org.expeditee.stats.TreeStats


Created ItemsList class to wrap ArrayList<Item>. Frames now use this new class to store its body list (used for display) as well as its primaryBody and surrogateBody.

-> org.expeditee.agents.Format
-> org.expeditee.agents.HFormat
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gui.Frame
-> org.expeditee.gui.FrameUtils


Refactorted Frame.setResort(bool) to Frame.invalidateSorted() to better function how it is intended to with a more accurate name.

-> org.expeditee.agents.Sort


When writing out .exp files and getting attributes to respond to LEFT + RIGHT click, boolean items are by default true. This has always been the case. An ammendment to this is that defaults can now be established.
Also added 'EnterClick' functionality. If cursored over a item with this property and you press enter, it acts as if you have clicked on it instead.

-> org.expeditee.assets.resources-public.framesets.authentication.1.exp to 6.exp
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gio.input.KBMInputEvent
-> org.expeditee.gio.javafx.JavaFXConversions
-> org.expeditee.gio.swing.SwingConversions
-> org.expeditee.gui.AttributeUtils
-> org.expeditee.io.Conversion
-> org.expeditee.io.DefaultFrameWriter
-> org.expeditee.items.Item


Fixed a bug caused by calling Math.abs on Integer.MIN_VALUE returning unexpected result. Due to zero being a thing, you cannot represent Math.abs(Integer.MIN_VALUE) in a Integer object. The solution is to use Integer.MIN_VALUE + 1 instead of Integer.MIN_VALUE.

-> org.expeditee.core.bounds.CombinationBounds
-> org.expeditee.io.flowlayout.DimensionExtent


Recoded the contains function in EllipticalBounds so that intersection tests containing circles work correctly.

-> org.expeditee.core.bounds.EllipticalBounds


Added toString() to PolygonBounds to allow for useful printing during debugging.

-> org.expeditee.core.bounds.PolygonBounds

Implemented Surrogate Mode!

-> org.expeditee.encryption.io.EncryptedExpReader
-> org.expeditee.encryption.io.EncryptedExpWriter
-> org.expeditee.encryption.items.surrogates.EncryptionDetail
-> org.expeditee.encryption.items.surrogates.Label
-> org.expeditee.gui.FrameUtils
-> org.expeditee.gui.ItemsList
-> org.expeditee.items.Item
-> org.expeditee.items.Text


???? Use Integer.MAX_VALUE cast to a float instead of Float.MAX_VALUE. This fixed some bug which I cannot remember.

-> org.expeditee.gio.TextLayoutManager
-> org.expeditee.gio.swing.SwingTextLayoutManager


Improved solution for dealing with the F10 key taking focus away from Expeditee due to it being a assessibility key.

-> org.expeditee.gio.swing.SwingInputManager


Renamed variable visibleItems in FrameGraphics.paintFrame to itemsToPaintCanditates to better represent functional intent.

-> org.expeditee.gui.FrameGraphics


Improved checking for if personal resources exist before recreating them

-> org.expeditee.gui.FrameIO


Repeated messages to message bay now have a visual feedback instead of just a beep. This visual feedback is in the form of a count of the amount of times it has repeated.

-> org.expeditee.gui.MessageBay


Updated comment on the Vector class to explain what vectors are.

-> org.expeditee.gui.Vector


Added constants to represent all of the property keys in DefaultFrameReader and DefaultFrameWriter.

-> org.expeditee.io.DefaultFrameReader
-> org.expeditee.io.DefaultFrameWriter


Updated the KeyList setting to be more heirarcial with how users will store their Secrets.

-> org.expeditee.settings.identity.secrets.KeyList

File size: 7.3 KB
Line 
1package org.expeditee.encryption.items.surrogates;
2
3import java.util.ArrayList;
4import java.util.Arrays;
5import java.util.Base64;
6import java.util.List;
7import java.util.function.Predicate;
8import java.util.stream.Collectors;
9import java.util.stream.Stream;
10
11import org.expeditee.gui.ItemsList;
12import org.expeditee.items.Item;
13import org.expeditee.items.Text;
14import org.expeditee.settings.identity.secrets.KeyList;
15
16public class Label {
17
18 private static int surrogateStep = -1;
19
20 public static LabelResult getLabel(String label) {
21 Text[] userLabels = KeyList.UserLabels.get();
22 Text labelText = null;
23 for (Text userLabel : userLabels) {
24 if (userLabel.getText().equals(label)) {
25 labelText = userLabel;
26 break;
27 }
28 }
29
30 if (labelText == null) {
31 return unableToFindLabelResult(label);
32 } else {
33 List<String> data = labelText.getData();
34 if (data == null || data.isEmpty()) {
35 return unableToFindLabelResult(label);
36 }
37 String dataEntry = data.get(0);
38
39 if (dataEntry.contains("{")) {
40 return partialKeyResult(label, dataEntry);
41 } else {
42 return fullKeyResult(label, dataEntry);
43 }
44 }
45 }
46
47 public static void progressSurrogateMode() {
48 surrogateStep += 1;
49 }
50
51 public static void resetSurrogateMode() {
52 surrogateStep = -1;
53 }
54
55 public static List<String> getAccessibleLabelsNames(ItemsList itemsList) {
56 Text[] userLabels = KeyList.UserLabels.get();
57 Stream<String> accessibleUserWideLabels = Arrays.asList(userLabels).stream().map(label -> label.getText());
58
59 Predicate<Item> isLabelWithoutEncryptionLabel = item -> item.getEncryptionLabel() == null || item.getEncryptionLabel().isEmpty();
60 itemsList.removeIf(isLabelWithoutEncryptionLabel);
61 Stream<String> accessibleFrameLocalLabels = itemsList.underlying().stream().map(item -> item.getEncryptionLabel()).distinct();
62
63 List<String> accessibleLabelsUnion = accessibleUserWideLabels.collect(Collectors.toList());
64 accessibleLabelsUnion.retainAll(accessibleFrameLocalLabels.collect(Collectors.toList()));
65
66 if (surrogateStep > -1 && surrogateStep < accessibleLabelsUnion.size()) {
67 String surrogateModeFilter = accessibleLabelsUnion.get(surrogateStep);
68 List<String> single = new ArrayList<String>();
69 single.add(surrogateModeFilter);
70 return single;
71 } else {
72 resetSurrogateMode();
73 }
74
75 return accessibleLabelsUnion;
76 }
77
78 private static LabelResult partialKeyResult(String label, String dataEntry) {
79 dataEntry = dataEntry.substring(dataEntry.indexOf('}') + 1).trim();
80 LabelResult res = LabelResult.SuccessResolveLabelToPartialKey;
81 res.name = label;
82 return res;
83 }
84
85 private static LabelResult unableToFindLabelResult(String label) {
86 LabelResult res = LabelResult.ErrorUnableToFindLabel;
87 res.name = label;
88 return res;
89 }
90
91 private static LabelResult fullKeyResult(String label, String dataEntry) {
92 try {
93 LabelResult res = LabelResult.SuccessResolveLabelToKey;
94 res.key = Base64.getDecoder().decode(dataEntry);
95 res.name = label;
96 return res;
97 } catch (IllegalArgumentException e) {
98 return LabelResult.ErrorUnableToFindLabel;
99 }
100 }
101
102 //private static Map<LabelResult, LabelAccess> labelCache = new LinkedHashMap<LabelResult, LabelAccess>();
103 //private static int surrogateStep = -1;
104 //private static final Predicate<? super LabelResult> isAccessible = a -> labelCache.get(a).allowed;
105
106// public static LabelResult resolveKey(String label) {
107// Stream<LabelResult> stream = labelCache.keySet().stream();
108// stream = stream.filter(res -> res.name.equals(label));
109// if (stream.count() == 0) {
110// return resolveKeyWorker(label);
111// } else {
112// LabelResult labelResult = stream.collect(Collectors.toList()).get(0);
113// LabelAccess accessible = labelCache.get(labelResult);
114// if (accessible.allowed) { return labelResult; }
115// else { return LabelResult.ErrorForbiddenLabel; }
116// }
117// }
118// private static LabelResult resolveKeyWorker(String label) {
119// Frame secretsFrame = getSecretsFrame();
120// if (secretsFrame == null) {
121// return LabelResult.ErrorUnableToFindSecretsFrame;
122// }
123//
124// String data = getDataFromLabel(secretsFrame, label);
125// if (data == null) {
126// return LabelResult.ErrorUnableToFindLabel;
127// }
128//
129// if (data.contains("{")) {
130// data = data.substring(data.indexOf('}') + 1).trim();
131// LabelResult res = LabelResult.SuccessResolveLabelToPartialKey;
132// res.key = Base64.getDecoder().decode(data);
133// return res;
134// } else {
135// try {
136// LabelResult res = LabelResult.SuccessResolveLabelToKey;
137// res.key = Base64.getDecoder().decode(data);
138// res.name = label;
139// labelCache.put(res, new LabelAccess(true));
140// return res;
141// } catch (IllegalArgumentException e) {
142// return LabelResult.ErrorUnableToFindLabel;
143// }
144// }
145// }
146//
147// private static String getDataFromLabel(Frame frame, String label) {
148// Collection<Text> labels = frame.getTextItems();
149// labels.removeIf(lbl -> !lbl.getText().equals(label));
150// labels.removeIf(lbl -> lbl.getData() == null || lbl.getData().size() == 0);
151// if (labels.isEmpty()) { return null; }
152// Text labelItem = labels.iterator().next();
153// List<String> data = labelItem.getData();
154// if (data.isEmpty()) { return null; }
155// return data.get(0);
156// }
157//
158// private static Frame getSecretsFrame() {
159// String credentialsFrameName = UserSettings.ProfileName.get() +
160// AuthenticatorBrowser.CREDENTIALS_FRAME;
161// Frame credentialsFrame = FrameIO.LoadFrame(credentialsFrameName);
162// Collection<Text> textItems = credentialsFrame.getTextItems();
163// textItems.removeIf(t -> !t.getText().equals("Secrets"));
164// textItems.removeIf(t -> !t.hasLink());
165// if (textItems.isEmpty()) {
166// return null;
167// }
168// Text linkToSecretsFrame = textItems.iterator().next();
169// if (!linkToSecretsFrame.hasLink()) {
170// return null;
171// }
172// Frame secretsFrame = FrameIO.LoadFrame(linkToSecretsFrame.getParent().getFramesetName() + linkToSecretsFrame.getLink());
173// return secretsFrame;
174// }
175//
176// private static class LabelAccess {
177// public final boolean allowedDefault;
178// public boolean allowed;
179//
180// public LabelAccess(boolean value) {
181// allowedDefault = value;
182// allowed = allowedDefault;
183// }
184// }
185
186 public enum LabelResult {
187 SuccessResolveLabelToKey,
188 SuccessResolveLabelToPartialKey,
189 ErrorUnableToFindSecretsFrame,
190 ErrorUnableToFindLabel,
191 ErrorForbiddenLabel;
192
193 public byte[] key;
194 public String name;
195
196 @Override
197 public String toString() {
198 switch (this) {
199 case SuccessResolveLabelToKey:
200 return "Resolved label to key: " + Base64.getEncoder().encodeToString(key);
201 case SuccessResolveLabelToPartialKey:
202 return "Resolved label to slice of a key: " + Base64.getEncoder().encodeToString(key);
203 case ErrorUnableToFindSecretsFrame:
204 return "Unable to find your Secrets Frame.";
205 case ErrorUnableToFindLabel:
206 return "Unable to resolve label to encrypt/decrypt frame. Label: " + name;
207 case ErrorForbiddenLabel:
208 return "Whilst you have the key for label " + name + " ; you are not allowed to use it.";
209 }
210
211 String message = "Was the list of possible enum results updated without nessasary changes to the toString() function?";
212 throw new IllegalArgumentException(message);
213 }
214 }
215}
Note: See TracBrowser for help on using the repository browser.