Skip to content

Commit

Permalink
Rename JOSEObjectPair to MutableJOSEObject.
Browse files Browse the repository at this point in the history
  • Loading branch information
DolphFlynn committed Dec 26, 2022
1 parent 120b345 commit baaf223
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/main/java/burp/AnnotationsModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import burp.api.montoya.core.ByteArray;
import burp.api.montoya.utilities.ByteUtils;
import com.blackberry.jwteditor.model.config.ProxyConfig;
import com.blackberry.jwteditor.model.jose.JOSEObjectPair;
import com.blackberry.jwteditor.model.jose.JWS;
import com.blackberry.jwteditor.model.jose.MutableJOSEObject;

import static burp.api.montoya.core.Annotations.annotations;
import static com.blackberry.jwteditor.model.jose.JOSEObjectFinder.extractJOSEObjects;
Expand Down Expand Up @@ -52,8 +52,8 @@ private Counts countJOSEObjects(ByteArray message) {
int jwsCount = 0;
int jweCount = 0;

for (JOSEObjectPair joseObjectPair : extractJOSEObjects(messageString)) {
if (joseObjectPair.getModified() instanceof JWS) {
for (MutableJOSEObject mutableJoseObject : extractJOSEObjects(messageString)) {
if (mutableJoseObject.getModified() instanceof JWS) {
jwsCount++;
} else {
jweCount++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class JOSEObjectFinder {
* @param text text block
* @return list of JOSEObjectPairs
*/
public static List<JOSEObjectPair> extractJOSEObjects(String text) {
List<JOSEObjectPair> joseObjects = new ArrayList<>();
public static List<MutableJOSEObject> extractJOSEObjects(String text) {
List<MutableJOSEObject> joseObjects = new ArrayList<>();

Set<String> candidates = findCandidateJoseObjectsWithin(text);

Expand All @@ -49,8 +49,8 @@ public static List<JOSEObjectPair> extractJOSEObjects(String text) {
Optional<JWE> jwe = parseJWE(candidate);
Optional<JWS> jws = jwe.isEmpty() ? parseJWS(candidate) : Optional.empty();

jwe.ifPresent(value -> joseObjects.add(new JOSEObjectPair(candidate, value)));
jws.ifPresent(value -> joseObjects.add(new JOSEObjectPair(candidate, value)));
jwe.ifPresent(value -> joseObjects.add(new MutableJOSEObject(candidate, value)));
jws.ifPresent(value -> joseObjects.add(new MutableJOSEObject(candidate, value)));
}

return joseObjects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Class for a JOSE object change set
*/
public class JOSEObjectPair {
public class MutableJOSEObject {
private final String original;
private JOSEObject modified;

Expand All @@ -31,7 +31,7 @@ public class JOSEObjectPair {
* @param original the original compact serialized JOSE object
* @param modified the parsed and updated JOSEObject
*/
public JOSEObjectPair(String original, JOSEObject modified) {
public MutableJOSEObject(String original, JOSEObject modified) {
this.original = original;
this.modified = modified;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
package com.blackberry.jwteditor.presenter;

import com.blackberry.jwteditor.model.jose.JOSEObject;
import com.blackberry.jwteditor.model.jose.JOSEObjectPair;
import com.blackberry.jwteditor.model.jose.JWE;
import com.blackberry.jwteditor.model.jose.JWS;
import com.blackberry.jwteditor.model.jose.MutableJOSEObject;
import com.blackberry.jwteditor.model.keys.Key;
import com.blackberry.jwteditor.operations.Operations;
import com.blackberry.jwteditor.utils.JSONUtils;
Expand Down Expand Up @@ -52,7 +52,7 @@ public class EditorPresenter extends Presenter {
private final PresenterStore presenters;
private final EditorView view;

private final List<JOSEObjectPair> joseObjectPairs;
private final List<MutableJOSEObject> mutableJoseObjects;

String message;

Expand All @@ -69,7 +69,7 @@ public EditorPresenter(EditorView view, PresenterStore presenters) {
this.presenters = presenters;
presenters.register(this);

joseObjectPairs = new ArrayList<>();
mutableJoseObjects = new ArrayList<>();
}

/**
Expand All @@ -91,13 +91,13 @@ public void setMessage(String content){

// Save the input text and clear existing JOSE objects
message = content;
joseObjectPairs.clear();
mutableJoseObjects.clear();

// Extract JOSE Objects from the text, build a change set and add them to the dropdown
List<JOSEObjectPair> joseObjects = extractJOSEObjects(content);
List<MutableJOSEObject> joseObjects = extractJOSEObjects(content);
String[] joseObjectStrings = new String[joseObjects.size()];
for(int i = 0; i < joseObjects.size(); i++){
joseObjectPairs.add(joseObjects.get(i));
mutableJoseObjects.add(joseObjects.get(i));

// Truncate the JOSE object for display
String serializedJWT = joseObjects.get(i).getOriginal();
Expand Down Expand Up @@ -458,10 +458,10 @@ public String getMessage() {
List<String> replacementList = new ArrayList<>();

//Add a replacement pair to the lists if the JOSEObjectPair has changed
for(JOSEObjectPair joseObjectPair: joseObjectPairs){
if(joseObjectPair.changed()) {
searchList.add(joseObjectPair.getOriginal());
replacementList.add(joseObjectPair.getModified().serialize());
for(MutableJOSEObject mutableJoseObject : mutableJoseObjects){
if(mutableJoseObject.changed()) {
searchList.add(mutableJoseObject.getOriginal());
replacementList.add(mutableJoseObject.getModified().serialize());
}
}

Expand All @@ -481,8 +481,8 @@ public String getMessage() {
* @return true if changes have been made in the editor
*/
public boolean isModified() {
for(JOSEObjectPair joseObjectPair: joseObjectPairs){
if(joseObjectPair.changed()){
for(MutableJOSEObject mutableJoseObject : mutableJoseObjects){
if(mutableJoseObject.changed()){
return true;
}
}
Expand All @@ -497,8 +497,8 @@ public void onSelectionChanged() {
selectionChanging = true;

// Get the JOSEObject pair corresponding to the selected dropdown entry index
JOSEObjectPair joseObjectPair = joseObjectPairs.get(view.getSelected());
JOSEObject joseObject = joseObjectPair.getModified();
MutableJOSEObject mutableJoseObject = mutableJoseObjects.get(view.getSelected());
JOSEObject joseObject = mutableJoseObject.getModified();

// Change to JWE/JWS mode based on the newly selected JOSEObject
if(joseObject instanceof JWS){
Expand All @@ -519,14 +519,14 @@ public void onSelectionChanged() {
*/
public void componentChanged() {
// Get the currently selected object
JOSEObjectPair joseObjectPair = joseObjectPairs.get(view.getSelected());
MutableJOSEObject mutableJoseObject = mutableJoseObjects.get(view.getSelected());

//Serialize the text/hex entries to a JWS/JWE in compact form, depending on the editor mode
JOSEObject joseObject = view.getMode() == EditorView.TAB_JWS ? getJWS() : getJWE();
//Update the JOSEObjectPair with the change
joseObjectPair.setModified(joseObject);
mutableJoseObject.setModified(joseObject);
//Highlight the serialized text as changed if it differs from the original, and the change wasn't triggered by onSelectionChanging
view.setSerialized(joseObject.serialize(), joseObjectPair.changed() && !selectionChanging);
view.setSerialized(joseObject.serialize(), mutableJoseObject.changed() && !selectionChanging);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/com/blackberry/jwteditor/JOSEParserTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

package com.blackberry.jwteditor;

import com.blackberry.jwteditor.model.jose.JOSEObjectPair;
import com.blackberry.jwteditor.model.jose.JWE;
import com.blackberry.jwteditor.model.jose.JWS;
import com.blackberry.jwteditor.model.jose.MutableJOSEObject;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Expand Down Expand Up @@ -90,7 +90,7 @@ private static Stream<String> invalidJwe() {
@ParameterizedTest
@MethodSource("validJws")
void testValidJWS(String joseObjectString) {
List<JOSEObjectPair> joseObjects = extractJOSEObjects(joseObjectString);
List<MutableJOSEObject> joseObjects = extractJOSEObjects(joseObjectString);

assertThat(joseObjects).hasSize(1);
assertThat(joseObjects.get(0).getModified()).isInstanceOf(JWS.class);
Expand All @@ -105,7 +105,7 @@ void testDetectValidJWS(String joseObjectString) {
@ParameterizedTest
@MethodSource("invalidJws")
void testInvalidJWS(String joseObjectString) {
List<JOSEObjectPair> joseObjects = extractJOSEObjects(joseObjectString);
List<MutableJOSEObject> joseObjects = extractJOSEObjects(joseObjectString);

assertThat(joseObjects).isEmpty();
}
Expand All @@ -120,7 +120,7 @@ void testDetectInvalidJWS(String joseObjectString) {
@ParameterizedTest
@MethodSource("validJwe")
void testValidJWE(String joseObjectString) {
List<JOSEObjectPair> joseObjects = extractJOSEObjects(joseObjectString);
List<MutableJOSEObject> joseObjects = extractJOSEObjects(joseObjectString);

assertThat(joseObjects).hasSize(1);
assertThat(joseObjects.get(0).getModified()).isInstanceOf(JWE.class);
Expand All @@ -135,7 +135,7 @@ void testDetectValidJWE(String joseObjectString) {
@ParameterizedTest
@MethodSource("invalidJwe")
void testInvalidJWE(String joseObjectString) {
List<JOSEObjectPair> joseObjects = extractJOSEObjects(joseObjectString);
List<MutableJOSEObject> joseObjects = extractJOSEObjects(joseObjectString);

assertThat(joseObjects).isEmpty();
}
Expand Down

0 comments on commit baaf223

Please sign in to comment.