- Timestamp:
- 07/24/19 11:23:45 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/encryption/io/EncryptedExpWriter.java
r1414 r1415 23 23 import org.expeditee.encryption.CryptographyConstants; 24 24 import org.expeditee.encryption.items.surrogates.EncryptionDetail; 25 import org.expeditee.encryption.items.surrogates.EncryptionDetail.Type; 25 26 import org.expeditee.encryption.items.surrogates.Label; 26 27 import org.expeditee.encryption.items.surrogates.Label.LabelResult; 27 28 import org.expeditee.gui.Frame; 29 import org.expeditee.gui.Frame.BodyType; 28 30 import org.expeditee.gui.MessageBay; 29 31 import org.expeditee.io.Conversion; … … 62 64 } 63 65 } else { 64 LabelResult res = Label. resolveKey(label);66 LabelResult res = Label.getLabel(label); 65 67 if (res == LabelResult.SuccessResolveLabelToKey) { 66 68 byte[] keyBytes = res.key; … … 94 96 95 97 // write item 96 writeItemData(frame );98 writeItemData(frame, true); 97 99 writeTerminator(); 98 99 100 // write lines and constraints 100 101 writeLineData(); 101 102 writeTerminator(); 102 103 writeConstraintData(); 103 writeTerminator(); 104 104 105 // write surrogate items 106 if (frame.hasSurrogates()) { 107 writeSurrogateTerminator(); 108 writeItemData(frame, false); 109 writeTerminator(); 110 } else { 111 writeTerminator(); 112 } 113 105 114 writeLine(SessionStats.getFrameEventList(frame)); 106 115 } … … 126 135 127 136 protected void writeClass(Item toWrite) throws IOException { 137 if (toWrite instanceof Text && toWrite.getText().equals("Content for Label Two")) { 138 System.err.println("EncryptedExpWriter::writeClass::breakpoint"); 139 } else if (toWrite instanceof Text && toWrite.getText().equals("Encrypted") && toWrite.getPrimary().getText().equals("Content for Label One")) { 140 System.err.println("EncryptedExpWriter::writeClass::breakpoint"); 141 } 142 128 143 LinkedHashMap<Character,Method> itemTags = new LinkedHashMap<Character, Method>(getItemTags()); 129 144 LinkedHashMap<String,Method> itemTagsExt = new LinkedHashMap<String, Method>(getItemTagsExt()); … … 149 164 } 150 165 EncryptionDetail encryptionDetail = toWrite.getEncryptionDetailForTag(tag + ""); 151 152 switch(encryptionDetail) { 166 Type encryptionDetailType = encryptionDetail.getEncryptionDetailType(); 167 168 switch(encryptionDetailType) { 153 169 case UnencryptedOnSave: 154 170 writeTagUnencryptedOnSave(toWrite, param, tags, tag); … … 166 182 } 167 183 168 private void writeItemData(Frame frame ) throws IOException {184 private void writeItemData(Frame frame, boolean primaryItems) throws IOException { 169 185 // write each item in the frame 170 for (Item i : frame.getItemsToSave()) { 186 BodyType bodyType = primaryItems ? BodyType.PrimaryBody : BodyType.SurrogateBody; 187 for (Item i : frame.getItemsToSave(bodyType)) { 171 188 assert (!(i instanceof Line)); 172 189 writeItem(i); … … 176 193 assert (!(i instanceof Line)); 177 194 writeItem(i); 178 }179 180 // write out the surrogates181 List<Item> surrogates = frame.getSurrogateItemsToSave();182 if (!surrogates.isEmpty()) {183 writeSurrogateTerminator();184 for (Item i: surrogates) {185 assert (!(i instanceof Line));186 writeItem(i);187 }188 195 } 189 196 } … … 194 201 BinaryOperator<Boolean> trueExists = (a, b) -> a || b; 195 202 boolean surrogatesInherit = surrogateItems.stream().map(isTagInherited).collect(Collectors.reducing(trueExists)).get(); 196 if (surrogatesInherit && 197 Label.resolveKey(toWrite.getEncryptionLabel()) == LabelResult.SuccessResolveLabelToKey) { 198 toWrite.setEncryptionDetailForTag(tag + "", EncryptionDetail.UnencryptedOnSave); 203 boolean userHasKey = Label.getLabel(toWrite.getEncryptionLabel()) == LabelResult.SuccessResolveLabelToKey; 204 205 if (!surrogatesInherit && userHasKey) { 206 EncryptionDetail reencryptOnSave = new EncryptionDetail(EncryptionDetail.Type.ReencryptOnSave); 207 toWrite.setEncryptionDetailForTag(tag + "", reencryptOnSave); 208 writeTagReencryptOnSave(toWrite, tags, tag); 209 } else { 210 EncryptionDetail unencryptedOnSave = new EncryptionDetail(EncryptionDetail.Type.UnencryptedOnSave); 211 toWrite.setEncryptionDetailForTag(tag + "", unencryptedOnSave); 199 212 writeTagUnencryptedOnSave(toWrite, new Object[] {}, tags, tag); 200 } else {201 toWrite.setEncryptionDetailForTag(tag + "", EncryptionDetail.ReencryptOnSave);202 writeTagReencryptOnSave(toWrite, tags, tag);203 213 } 204 214 } … … 207 217 Method toRun = tags.get(tag); 208 218 Class<?> declarer = toRun.getDeclaringClass(); 209 LabelResult res = Label. resolveKey(toWrite.getEncryptionLabel());219 LabelResult res = Label.getLabel(toWrite.getEncryptionLabel()); 210 220 if (declarer.isAssignableFrom(toWrite.getClass()) && res == LabelResult.SuccessResolveLabelToKey) { 211 221 try {
Note:
See TracChangeset
for help on using the changeset viewer.