|
@@ -42,84 +42,186 @@ describe('StringArrayCallsWrapperTemplate', () => {
|
|
|
});
|
|
|
|
|
|
describe('Variant #1: `base64` encoding', () => {
|
|
|
- const index: string = '0x0';
|
|
|
- const expectedDecodedValue: string = 'test1';
|
|
|
-
|
|
|
- let decodedValue: string;
|
|
|
-
|
|
|
- before(() => {
|
|
|
- const atobPolyfill = format(AtobTemplate(), {
|
|
|
- atobFunctionName
|
|
|
- });
|
|
|
- const atobDecodeTemplate: string = format(
|
|
|
- StringArrayBase64DecodeTemplate(randomGenerator),
|
|
|
- {
|
|
|
- atobPolyfill,
|
|
|
- atobFunctionName,
|
|
|
- selfDefendingCode: '',
|
|
|
- stringArrayCallsWrapperName
|
|
|
- }
|
|
|
- );
|
|
|
- const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), {
|
|
|
- decodeCodeHelperTemplate: atobDecodeTemplate,
|
|
|
- stringArrayCallsWrapperName,
|
|
|
- stringArrayName
|
|
|
- });
|
|
|
-
|
|
|
- decodedValue = Function(`
|
|
|
+ describe('Variant #1: index shift amount is `0`', () => {
|
|
|
+ const index: string = '0x0';
|
|
|
+
|
|
|
+ const indexShiftAmount: number = 0;
|
|
|
+
|
|
|
+ const expectedDecodedValue: string = 'test1';
|
|
|
+
|
|
|
+ let decodedValue: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const atobPolyfill = format(AtobTemplate(), {
|
|
|
+ atobFunctionName
|
|
|
+ });
|
|
|
+ const atobDecodeTemplate: string = format(
|
|
|
+ StringArrayBase64DecodeTemplate(randomGenerator),
|
|
|
+ {
|
|
|
+ atobPolyfill,
|
|
|
+ atobFunctionName,
|
|
|
+ selfDefendingCode: '',
|
|
|
+ stringArrayCallsWrapperName
|
|
|
+ }
|
|
|
+ );
|
|
|
+ const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), {
|
|
|
+ decodeCodeHelperTemplate: atobDecodeTemplate,
|
|
|
+ indexShiftAmount,
|
|
|
+ stringArrayCallsWrapperName,
|
|
|
+ stringArrayName
|
|
|
+ });
|
|
|
+
|
|
|
+ decodedValue = Function(`
|
|
|
var ${stringArrayName} = ['${cryptUtilsSwappedAlphabet.btoa('test1')}'];
|
|
|
|
|
|
${stringArrayCallsWrapperTemplate}
|
|
|
|
|
|
return ${stringArrayCallsWrapperName}(${index});
|
|
|
`)();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should correctly return decoded value', () => {
|
|
|
+ assert.deepEqual(decodedValue, expectedDecodedValue);
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
- it('should correctly return decoded value', () => {
|
|
|
- assert.deepEqual(decodedValue, expectedDecodedValue);
|
|
|
+ describe('Variant #2: index shift amount is `5`', () => {
|
|
|
+ const index: string = '0x5';
|
|
|
+
|
|
|
+ const indexShiftAmount: number = 5;
|
|
|
+
|
|
|
+ const expectedDecodedValue: string = 'test1';
|
|
|
+
|
|
|
+ let decodedValue: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const atobPolyfill = format(AtobTemplate(), {
|
|
|
+ atobFunctionName
|
|
|
+ });
|
|
|
+ const atobDecodeTemplate: string = format(
|
|
|
+ StringArrayBase64DecodeTemplate(randomGenerator),
|
|
|
+ {
|
|
|
+ atobPolyfill,
|
|
|
+ atobFunctionName,
|
|
|
+ selfDefendingCode: '',
|
|
|
+ stringArrayCallsWrapperName
|
|
|
+ }
|
|
|
+ );
|
|
|
+ const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), {
|
|
|
+ decodeCodeHelperTemplate: atobDecodeTemplate,
|
|
|
+ indexShiftAmount,
|
|
|
+ stringArrayCallsWrapperName,
|
|
|
+ stringArrayName
|
|
|
+ });
|
|
|
+
|
|
|
+ decodedValue = Function(`
|
|
|
+ var ${stringArrayName} = ['${cryptUtilsSwappedAlphabet.btoa('test1')}'];
|
|
|
+
|
|
|
+ ${stringArrayCallsWrapperTemplate}
|
|
|
+
|
|
|
+ return ${stringArrayCallsWrapperName}(${index});
|
|
|
+ `)();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should correctly return decoded value', () => {
|
|
|
+ assert.deepEqual(decodedValue, expectedDecodedValue);
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('Variant #2: `rc4` encoding', () => {
|
|
|
- const index: string = '0x0';
|
|
|
- const key: string = 'key';
|
|
|
- const expectedDecodedValue: string = 'test1';
|
|
|
-
|
|
|
- let decodedValue: string;
|
|
|
-
|
|
|
- before(() => {
|
|
|
- const atobPolyfill = format(AtobTemplate(), {
|
|
|
- atobFunctionName
|
|
|
- });
|
|
|
- const rc4Polyfill = format(Rc4Template(), {
|
|
|
- atobFunctionName
|
|
|
- });
|
|
|
- const rc4decodeCodeHelperTemplate: string = format(
|
|
|
- StringArrayRC4DecodeTemplate(randomGenerator),
|
|
|
- {
|
|
|
- atobPolyfill,
|
|
|
- rc4Polyfill,
|
|
|
- selfDefendingCode: '',
|
|
|
- stringArrayCallsWrapperName
|
|
|
- }
|
|
|
- );
|
|
|
- const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), {
|
|
|
- decodeCodeHelperTemplate: rc4decodeCodeHelperTemplate,
|
|
|
- stringArrayCallsWrapperName,
|
|
|
- stringArrayName
|
|
|
- });
|
|
|
-
|
|
|
- decodedValue = Function(`
|
|
|
+ describe('Variant #1: index shift amount is `0`', () => {
|
|
|
+ const index: string = '0x0';
|
|
|
+ const key: string = 'key';
|
|
|
+
|
|
|
+ const indexShiftAmount: number = 0;
|
|
|
+
|
|
|
+ const expectedDecodedValue: string = 'test1';
|
|
|
+
|
|
|
+ let decodedValue: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const atobPolyfill = format(AtobTemplate(), {
|
|
|
+ atobFunctionName
|
|
|
+ });
|
|
|
+ const rc4Polyfill = format(Rc4Template(), {
|
|
|
+ atobFunctionName
|
|
|
+ });
|
|
|
+ const rc4decodeCodeHelperTemplate: string = format(
|
|
|
+ StringArrayRC4DecodeTemplate(randomGenerator),
|
|
|
+ {
|
|
|
+ atobPolyfill,
|
|
|
+ rc4Polyfill,
|
|
|
+ selfDefendingCode: '',
|
|
|
+ stringArrayCallsWrapperName
|
|
|
+ }
|
|
|
+ );
|
|
|
+ const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), {
|
|
|
+ decodeCodeHelperTemplate: rc4decodeCodeHelperTemplate,
|
|
|
+ indexShiftAmount,
|
|
|
+ stringArrayCallsWrapperName,
|
|
|
+ stringArrayName
|
|
|
+ });
|
|
|
+
|
|
|
+ decodedValue = Function(`
|
|
|
var ${stringArrayName} = ['${cryptUtilsSwappedAlphabet.btoa(cryptUtilsSwappedAlphabet.rc4('test1', key))}'];
|
|
|
|
|
|
${stringArrayCallsWrapperTemplate}
|
|
|
|
|
|
return ${stringArrayCallsWrapperName}('${index}', '${key}');
|
|
|
`)();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should correctly return decoded value', () => {
|
|
|
+ assert.deepEqual(decodedValue, expectedDecodedValue);
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
- it('should correctly return decoded value', () => {
|
|
|
- assert.deepEqual(decodedValue, expectedDecodedValue);
|
|
|
+ describe('Variant #2: index shift amount is `5`', () => {
|
|
|
+ const index: string = '0x5';
|
|
|
+ const key: string = 'key';
|
|
|
+
|
|
|
+ const indexShiftAmount: number = 5;
|
|
|
+
|
|
|
+ const expectedDecodedValue: string = 'test1';
|
|
|
+
|
|
|
+ let decodedValue: string;
|
|
|
+
|
|
|
+ before(() => {
|
|
|
+ const atobPolyfill = format(AtobTemplate(), {
|
|
|
+ atobFunctionName
|
|
|
+ });
|
|
|
+ const rc4Polyfill = format(Rc4Template(), {
|
|
|
+ atobFunctionName
|
|
|
+ });
|
|
|
+ const rc4decodeCodeHelperTemplate: string = format(
|
|
|
+ StringArrayRC4DecodeTemplate(randomGenerator),
|
|
|
+ {
|
|
|
+ atobPolyfill,
|
|
|
+ rc4Polyfill,
|
|
|
+ selfDefendingCode: '',
|
|
|
+ stringArrayCallsWrapperName
|
|
|
+ }
|
|
|
+ );
|
|
|
+ const stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), {
|
|
|
+ decodeCodeHelperTemplate: rc4decodeCodeHelperTemplate,
|
|
|
+ indexShiftAmount,
|
|
|
+ stringArrayCallsWrapperName,
|
|
|
+ stringArrayName
|
|
|
+ });
|
|
|
+
|
|
|
+ decodedValue = Function(`
|
|
|
+ var ${stringArrayName} = ['${cryptUtilsSwappedAlphabet.btoa(cryptUtilsSwappedAlphabet.rc4('test1', key))}'];
|
|
|
+
|
|
|
+ ${stringArrayCallsWrapperTemplate}
|
|
|
+
|
|
|
+ return ${stringArrayCallsWrapperName}('${index}', '${key}');
|
|
|
+ `)();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should correctly return decoded value', () => {
|
|
|
+ assert.deepEqual(decodedValue, expectedDecodedValue);
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
|