Skip to content

Commit

Permalink
Merge pull request #18 from adorsys/sync-develop
Browse files Browse the repository at this point in the history
Sync develop with main
  • Loading branch information
Ogenbertrand authored Oct 2, 2024
2 parents eb4a26a + 8c324dd commit 2acdc46
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/main/java/de/adorsys/sdjwt/vp/SdJwtVP.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,16 @@ public static SdJwtVP of(String sdJwtString) {
int disclosureStart = sdJwtString.indexOf(SdJwt.DELIMITER);
int disclosureEnd = sdJwtString.lastIndexOf(SdJwt.DELIMITER);

if (disclosureStart == -1) {
throw new IllegalArgumentException("SD-JWT is malformed, expected to end with " + SdJwt.DELIMITER);
}

String issuerSignedJWTString = sdJwtString.substring(0, disclosureStart);
String disclosuresString = sdJwtString.substring(disclosureStart + 1, disclosureEnd);
String disclosuresString = "";

if (disclosureEnd > disclosureStart) {
disclosuresString = sdJwtString.substring(disclosureStart + 1, disclosureEnd);
}

IssuerSignedJWT issuerSignedJWT = IssuerSignedJWT.fromJws(issuerSignedJWTString);

Expand Down
26 changes: 24 additions & 2 deletions src/test/java/de/adorsys/sdjwt/sdjwtvp/SdJwtVPTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;


/**
* @author <a href="mailto:[email protected]">Francis Pouatcha</a>
*/
Expand Down Expand Up @@ -167,7 +170,7 @@ public void testS6_2_PresentationNegative() throws JOSEException, ParseException
// Verify with wrong public key from settings (issuer)
presenteSdJwtVP.getKeyBindingJWT().get().verifySignature(testSettings.issuerVerifierContext.verifier);
}

@Test
public void testS6_2_PresentationPartialDisclosure() throws ParseException, JOSEException {
String jwsType = "vc+sd-jwt";
Expand All @@ -186,4 +189,23 @@ public void testS6_2_PresentationPartialDisclosure() throws ParseException, JOSE
.verifySignature(TestSettings.verifierContextFrom(presenteSdJwtVP.getCnfClaim(), "ES256"));
}

}
@Test
public void testOf_validInput() {
String sdJwtString = TestUtils.readFileAsString(getClass(), "sdjwt/s6.2-presented-sdjwtvp.txt");
SdJwtVP sdJwtVP = SdJwtVP.of(sdJwtString);

assertNotNull(sdJwtVP);
assertEquals(4, sdJwtVP.getDisclosures().size());
}

@Test
public void testOf_MalformedSdJwt_ThrowsIllegalArgumentException() {
// Given
String malformedSdJwt = "issuer-signed-jwt"; // missing delimiter at the end

// When & Then
var exception = assertThrows(IllegalArgumentException.class, () -> SdJwtVP.of(malformedSdJwt));
assertEquals("SD-JWT is malformed, expected to end with ~", exception.getMessage());
}

}

0 comments on commit 2acdc46

Please sign in to comment.