-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from daanbreur/feat-itcon-parser
Create HITCON CTF parser
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { ParsedTask, Parser } from '.'; | ||
import { parseJsonStrict } from '../utils'; | ||
|
||
const HitconParser: Parser = { | ||
name: 'HITCONCTF parser', | ||
hint: 'paste hitcon /dashboard/challenge_data', | ||
parse(s): ParsedTask[] { | ||
const tasks: ParsedTask[] = []; | ||
const data = | ||
parseJsonStrict< | ||
[{ name: string; category: string; description: string }] | ||
>(s); | ||
if (data == null) { | ||
return []; | ||
} | ||
|
||
for (const challenge of data) { | ||
if (!challenge.description || !challenge.name) { | ||
continue; | ||
} | ||
|
||
tasks.push({ | ||
title: challenge.name, | ||
tags: challenge.category.split(','), | ||
description: challenge.description, | ||
}); | ||
} | ||
|
||
return tasks; | ||
}, | ||
isValid(s) { | ||
const data = | ||
parseJsonStrict< | ||
[{ name: string; category: string; description: string }] | ||
>(s); | ||
if (data == null || data.length < 1) { | ||
return false; | ||
} | ||
return ( | ||
data[0].name != null && | ||
data[0].category != null && | ||
data[0].description != null | ||
); | ||
}, | ||
}; | ||
|
||
export default HitconParser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters