Changeset 1413 for trunk/src/org/expeditee/encryption/items
- Timestamp:
- 06/25/19 13:57:37 (5 years ago)
- Location:
- trunk/src/org/expeditee/encryption/items/surrogates
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/encryption/items/surrogates/EncryptionDetail.java
r1408 r1413 2 2 3 3 public enum EncryptionDetail { 4 UnencryptedOnSave, ReencryptOnSave, UseUndecipheredValueOnSave; 4 // If the property needs to be unencrypted due to inheritance then do not try to encrypt it. 5 UnencryptedOnSave, 6 7 // If the property is not inherited by any surrogates then we can try to encrypt it. 8 // If we do not have key then default to UnencryptedOnSave. 9 ReencryptOnSave, 10 11 // If the property is no longer inherited by at least one surrogate then this value is present. 12 // If it turns out there is no longer any surrogates who inherit the value then this value can be replaced with ReencryptOnSave. 13 // Otherwise, this value must be replaced with UnencryptedOnSave. 14 InheritanceCheckOnSave, 15 16 // If we could not decrypt the value on load then EncryptionDetail.getUndecipheredValue() can be used to get the value for saving. 17 UseUndecipheredValueOnSave; 5 18 6 19 private String undecipheredValue = null; -
trunk/src/org/expeditee/encryption/items/surrogates/Label.java
r1409 r1413 1 1 package org.expeditee.encryption.items.surrogates; 2 2 3 import java.util.ArrayList; 3 4 import java.util.Base64; 4 5 import java.util.Collection; 6 import java.util.List; 7 import java.util.Set; 8 import java.util.stream.Collectors; 5 9 6 10 import org.expeditee.auth.AuthenticatorBrowser; 11 import org.expeditee.gui.DisplayController; 7 12 import org.expeditee.gui.Frame; 8 13 import org.expeditee.gui.FrameIO; 14 import org.expeditee.gui.MessageBay; 15 import org.expeditee.items.Item; 9 16 import org.expeditee.items.Text; 10 17 import org.expeditee.settings.UserSettings; … … 12 19 public class Label { 13 20 21 private static List<LabelResult> labelCache = new ArrayList<LabelResult>(); 22 private static List<String> forbiddenLabels = new ArrayList<String>(); 23 14 24 public static LabelResult resolveKey(String label) { 25 26 if (forbiddenLabels.contains(label)) { 27 return LabelResult.ErrorUnableToFindLabel; 28 } 29 30 LabelResult fromCache = getFromCache(label); 31 if (fromCache != null) { 32 return fromCache; 33 } 34 35 15 36 String credentialsFrameName = UserSettings.ProfileName.get() + 16 37 AuthenticatorBrowser.CREDENTIALS_FRAME; … … 44 65 LabelResult res = LabelResult.SuccessResolveLabelToKey; 45 66 res.key = Base64.getDecoder().decode(data); 67 res.name = label; 68 labelCache.add(res); 46 69 return res; 47 70 } catch (IllegalArgumentException e) { … … 50 73 } 51 74 } 75 76 public static void progressSurrogateMode() { 77 Collection<Item> allItems = DisplayController.getCurrentFrame().getAllItems(); 78 allItems.removeIf(item -> item.getEncryptionLabel() == null); 79 MessageBay.displayMessage("Encryption labels found on items on current frame: "); 80 Set<String> allLabels = allItems.stream().map(i -> i.getEncryptionLabel()).collect(Collectors.toSet()); 81 StringBuilder sb = new StringBuilder(); 82 for (String label: allLabels) { 83 sb.append(label + ","); 84 } 85 MessageBay.displayMessage(sb.deleteCharAt(sb.length() - 1).toString()); 86 } 87 88 public static void resetSurrogateMode() { 89 // TODO Auto-generated method stub 90 91 } 92 93 private static LabelResult getFromCache(String label) { 94 List<LabelResult> cacheCanditates = labelCache.stream().filter(labelResult -> labelResult.name.equals(label)).collect(Collectors.toList()); 95 if (!cacheCanditates.isEmpty()) { 96 return cacheCanditates.get(0); 97 } else { 98 return null; 99 } 100 } 101 102 // private static List<List<String>> permutation(List<String> strings, List<List<String>> acc) { 103 // for (int i = 0; i < strings.size(); i++) { 104 // 105 // } 106 // } 52 107 53 108 public enum LabelResult { … … 58 113 59 114 public byte[] key; 115 public String name; 60 116 61 117 @Override
Note:
See TracChangeset
for help on using the changeset viewer.