Skip to content

Commit

Permalink
Check validUntil & validFrom format on issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
aljones15 committed Dec 8, 2023
1 parent 401f83f commit 45cb8e1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,20 +635,22 @@ export function _checkCredential({
}
if(checkContextVersion({credential, version: 2.0})) {
// check if 'validUntil' and 'validFrom'
if(mode === 'verify') {
let {validUntil, validFrom} = credential;
if(validUntil) {
assertDateString({credential, prop: 'validUntil'});
let {validUntil, validFrom} = credential;
if(validUntil) {
assertDateString({credential, prop: 'validUntil'});
if(mode === 'verify') {
validUntil = new Date(credential.validUntil);
if(now > validUntil) {
throw new Error(
`The current date time (${now.toISOString()}) is after ` +
`"validUntil" (${credential.validUntil}).`);
}
}
if(validFrom) {
assertDateString({credential, prop: 'validFrom'});
// check if `now` is before `validFrom`
}
if(validFrom) {
assertDateString({credential, prop: 'validFrom'});
if(mode === 'verify') {
// check if `now` is before `validFrom`
validFrom = new Date(credential.validFrom);
if(now < validFrom) {
throw new Error(
Expand Down

0 comments on commit 45cb8e1

Please sign in to comment.