Ignore:
Timestamp:
06/25/19 13:57:37 (5 years ago)
Author:
bln4
Message:

Changed surrogates to work the way discussed with David. EncryptedExpReader/Writer updated to work with this.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/encryption/items/surrogates/Label.java

    r1409 r1413  
    11package org.expeditee.encryption.items.surrogates;
    22
     3import java.util.ArrayList;
    34import java.util.Base64;
    45import java.util.Collection;
     6import java.util.List;
     7import java.util.Set;
     8import java.util.stream.Collectors;
    59
    610import org.expeditee.auth.AuthenticatorBrowser;
     11import org.expeditee.gui.DisplayController;
    712import org.expeditee.gui.Frame;
    813import org.expeditee.gui.FrameIO;
     14import org.expeditee.gui.MessageBay;
     15import org.expeditee.items.Item;
    916import org.expeditee.items.Text;
    1017import org.expeditee.settings.UserSettings;
     
    1219public class Label {
    1320       
     21        private static List<LabelResult> labelCache = new ArrayList<LabelResult>();
     22        private static List<String> forbiddenLabels = new ArrayList<String>();
     23       
    1424        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               
    1536                String credentialsFrameName = UserSettings.ProfileName.get() +
    1637                                AuthenticatorBrowser.CREDENTIALS_FRAME;
     
    4465                                LabelResult res = LabelResult.SuccessResolveLabelToKey;
    4566                                res.key = Base64.getDecoder().decode(data);
     67                                res.name = label;
     68                                labelCache.add(res);
    4669                                return res;
    4770                        } catch (IllegalArgumentException e) {
     
    5073                }
    5174        }
     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//      }
    52107       
    53108        public enum LabelResult {
     
    58113               
    59114                public byte[] key;
     115                public String name;
    60116               
    61117                @Override
Note: See TracChangeset for help on using the changeset viewer.