Skip to content

Commit

Permalink
fix: add null check for dates
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafasalfiti committed Mar 12, 2024
1 parent 62c4417 commit 845aef1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,23 @@ public SignedJWT create(
public SignedJWT create(
Did didIssuer,
Did holderIssuer,
Date expDate,
LinkedHashMap<String, Object> vc,
IPrivateKey privateKey,
String keyId) {
final String issuer = didIssuer.toString();
final String subject = holderIssuer.toString();

final Date issueDate = Date.from(Instant.parse((String) vc.get("issuanceDate")));
// check if expirationDate is presented in VC then use it, otherwise null
final Date expireDateAsDate =
vc.containsKey("expirationDate")
? Date.from(Instant.parse((String) vc.get("expirationDate")))
: null;

// check if issuanceDate is presented in VC then use it, otherwise null
final Date issueDate =
vc.containsKey("issuanceDate")
? Date.from(Instant.parse((String) vc.get("issuanceDate")))
: null;

vc.remove(Verifiable.PROOF);

Expand All @@ -140,7 +149,7 @@ public SignedJWT create(
.issuer(issuer)
.subject(subject)
.claim("vc", vc)
.expirationTime(expDate)
.expirationTime(expireDateAsDate)
.issueTime(issueDate)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
package org.eclipse.tractusx.ssi.lib.serialization.jwt;

import com.nimbusds.jwt.SignedJWT;
import java.util.Date;
import org.eclipse.tractusx.ssi.lib.crypt.IPrivateKey;
import org.eclipse.tractusx.ssi.lib.model.did.Did;
import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential;
Expand All @@ -31,7 +30,6 @@ public interface SerializedJwtVCFactory {
SignedJWT createVCJwt(
Did issuer,
Did holder,
Date expDate,
VerifiableCredential credentials,
IPrivateKey privateKey,
String keyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
package org.eclipse.tractusx.ssi.lib.serialization.jwt;

import com.nimbusds.jwt.SignedJWT;
import java.util.Date;
import java.util.LinkedHashMap;
import lombok.RequiredArgsConstructor;
import org.eclipse.tractusx.ssi.lib.crypt.IPrivateKey;
Expand All @@ -38,12 +37,11 @@ public class SerializedJwtVCFactoryImpl implements SerializedJwtVCFactory {
public SignedJWT createVCJwt(
Did issuer,
Did holder,
Date expDate,
VerifiableCredential credentials,
IPrivateKey privateKey,
String keyId) {
var clonedVC = new LinkedHashMap<String, Object>();
clonedVC.putAll(credentials);
return signedJwtFactory.create(issuer, holder, expDate, clonedVC, privateKey, keyId);
return signedJwtFactory.create(issuer, holder, clonedVC, privateKey, keyId);
}
}

0 comments on commit 845aef1

Please sign in to comment.