Skip to content

Commit

Permalink
Add ångstromCTF parser
Browse files Browse the repository at this point in the history
Parsing challenges from https://angstromctf.com/
  • Loading branch information
peace-maker authored and XeR committed Sep 1, 2023
1 parent 34468ec commit e766b31
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
44 changes: 44 additions & 0 deletions front/src/ctfnote/parsers/angstrom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ParsedTask, Parser } from '.';
import { parseJson, parseJsonStrict } from '../utils';

const AngstromParser: Parser = {
name: 'ångstromCTF parser',
hint: 'paste api.angstromctf.com/competitions/XX/challenges with XX being the event id',

parse(s: string): ParsedTask[] {
const tasks = [];
const data =
parseJsonStrict<
Array<{ title: string; category: string; description: string }>
>(s);
if (!Array.isArray(data)) {
return [];
}
for (const task of data) {
if (!task.title || !task.category) {
continue;
}
tasks.push({
title: task.title,
category: task.category,
description: task.description,
});
}
return tasks;
},
isValid(s) {
const data =
parseJson<
Array<{ title: string; category: string; description: string }>
>(s);
return (
Array.isArray(data) &&
data.length > 0 &&
data[0].title != null &&
data[0].category != null &&
data[0].description != null
);
},
};

export default AngstromParser;
2 changes: 2 additions & 0 deletions front/src/ctfnote/parsers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import RawParser from './raw';
import HTBParser from './htb';
import PicoParser from './pico';
import justCTFParser from './justctf';
import AngstromParser from './angstrom';

export type ParsedTask = {
title: string;
Expand All @@ -26,4 +27,5 @@ export default [
HTBParser,
PicoParser,
justCTFParser,
AngstromParser,
];

0 comments on commit e766b31

Please sign in to comment.