Skip to content

Commit c231787

Browse files
committed
added flag logic and encryption
1 parent 75e6ca9 commit c231787

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

src/logic/flagDecorator.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { createFlag, stripFlag } from './flagDecorator';
2+
3+
describe('Flag Decorator', () => {
4+
it('should strip flag and leave the content', () => {
5+
const flag = createFlag('test');
6+
expect(stripFlag(flag)).toEqual('test');
7+
});
8+
9+
it('should throw error for splitting invalid flag', () => {
10+
const flag = 'test';
11+
expect(() => stripFlag(flag)).toThrow();
12+
});
13+
});

src/logic/flagDecorator.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { removePadding } from '@utils/padding';
2+
3+
export type Flag = `flag{${string}}`;
4+
5+
export const createFlag = (content: string): Flag => `flag{${content}}`;
6+
7+
export const isFlag = (str: string): str is Flag =>
8+
str.startsWith('flag{') && str.endsWith('}');
9+
10+
export const stripFlag = (flag: string) => {
11+
if (!isFlag(flag))
12+
throw new Error(`StripFlagError - invalid flag - ${flag}`);
13+
14+
return removePadding(flag, 'flag{', '}');
15+
};

src/logic/flagEncryption.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
describe('flagEncryption', () => {
2+
})

src/logic/flagEncryption.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { stripFlag } from '@logic/flagDecorator';
2+
3+
const PAD_START = 'encrypted{';
4+
const PAD_END = '}';
5+
6+
export const encryptFlag = (flag: string) => {
7+
const flagContent = stripFlag(flag);
8+
9+
return ;
10+
};
11+
12+
export const decryptFlag = (encryptedFlag: string) => {};

0 commit comments

Comments
 (0)