From dceb80d9aa45ea0f7b7039f43404a10d97d50bda Mon Sep 17 00:00:00 2001 From: marvin-j97 <33938500+marvin-j97@users.noreply.github.com> Date: Fri, 14 Jul 2023 01:55:02 +0200 Subject: [PATCH 1/5] feat: add file hasher --- components.d.ts | 1 + src/tools/file-hash/file-hash.e2e.spec.ts | 15 ++ src/tools/file-hash/file-hash.service.test.ts | 6 + src/tools/file-hash/file-hash.service.ts | 0 src/tools/file-hash/file-hash.vue | 149 ++++++++++++++++++ src/tools/file-hash/index.ts | 12 ++ src/tools/index.ts | 3 +- 7 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 src/tools/file-hash/file-hash.e2e.spec.ts create mode 100644 src/tools/file-hash/file-hash.service.test.ts create mode 100644 src/tools/file-hash/file-hash.service.ts create mode 100644 src/tools/file-hash/file-hash.vue create mode 100644 src/tools/file-hash/index.ts diff --git a/components.d.ts b/components.d.ts index 25148492..e457a0c5 100644 --- a/components.d.ts +++ b/components.d.ts @@ -51,6 +51,7 @@ declare module '@vue/runtime-core' { Encryption: typeof import('./src/tools/encryption/encryption.vue')['default'] EtaCalculator: typeof import('./src/tools/eta-calculator/eta-calculator.vue')['default'] FavoriteButton: typeof import('./src/components/FavoriteButton.vue')['default'] + FileHash: typeof import('./src/tools/file-hash/file-hash.vue')['default'] FormatTransformer: typeof import('./src/components/FormatTransformer.vue')['default'] GitMemo: typeof import('./src/tools/git-memo/git-memo.vue')['default'] 'GitMemo.content': typeof import('./src/tools/git-memo/git-memo.content.md')['default'] diff --git a/src/tools/file-hash/file-hash.e2e.spec.ts b/src/tools/file-hash/file-hash.e2e.spec.ts new file mode 100644 index 00000000..c44b7c91 --- /dev/null +++ b/src/tools/file-hash/file-hash.e2e.spec.ts @@ -0,0 +1,15 @@ +import { test, expect } from '@playwright/test'; + +test.describe('Tool - File hash', () => { + test.beforeEach(async ({ page }) => { + await page.goto('/file-hash'); + }); + + test('Has correct title', async ({ page }) => { + await expect(page).toHaveTitle('File hash - IT Tools'); + }); + + test('', async ({ page }) => { + + }); +}); \ No newline at end of file diff --git a/src/tools/file-hash/file-hash.service.test.ts b/src/tools/file-hash/file-hash.service.test.ts new file mode 100644 index 00000000..cf56c670 --- /dev/null +++ b/src/tools/file-hash/file-hash.service.test.ts @@ -0,0 +1,6 @@ +import { expect, describe, it } from 'vitest'; +// import { } from './file-hash.service'; +// +// describe('file-hash', () => { +// +// }) \ No newline at end of file diff --git a/src/tools/file-hash/file-hash.service.ts b/src/tools/file-hash/file-hash.service.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/tools/file-hash/file-hash.vue b/src/tools/file-hash/file-hash.vue new file mode 100644 index 00000000..23eac902 --- /dev/null +++ b/src/tools/file-hash/file-hash.vue @@ -0,0 +1,149 @@ + + + + + + + + + Click or drag a file to this area to upload + + + + + + + + + + + + + + + + + + + Copy + + + + + + diff --git a/src/tools/file-hash/index.ts b/src/tools/file-hash/index.ts new file mode 100644 index 00000000..c622d805 --- /dev/null +++ b/src/tools/file-hash/index.ts @@ -0,0 +1,12 @@ +import { Key } from '@vicons/tabler'; +import { defineTool } from '../tool'; + +export const tool = defineTool({ + name: 'File hash', + path: '/file-hash', + description: 'Calculate file hashes', + keywords: ['file', 'hash', 'md5', 'sha', 'crypto'], + component: () => import('./file-hash.vue'), + icon: Key, + createdAt: new Date('2023-07-13'), +}); diff --git a/src/tools/index.ts b/src/tools/index.ts index fb05045f..aa56c5f3 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -1,6 +1,7 @@ import { tool as base64FileConverter } from './base64-file-converter'; import { tool as base64StringConverter } from './base64-string-converter'; import { tool as basicAuthGenerator } from './basic-auth-generator'; +import { tool as fileHash } from './file-hash'; import { tool as passwordStrengthAnalyser } from './password-strength-analyser'; import { tool as yamlToToml } from './yaml-to-toml'; import { tool as jsonToToml } from './json-to-toml'; @@ -69,7 +70,7 @@ import { tool as xmlFormatter } from './xml-formatter'; export const toolsByCategory: ToolCategory[] = [ { name: 'Crypto', - components: [tokenGenerator, hashText, bcrypt, uuidGenerator, cypher, bip39, hmacGenerator, rsaKeyPairGenerator, passwordStrengthAnalyser], + components: [fileHash, tokenGenerator, hashText, bcrypt, uuidGenerator, cypher, bip39, hmacGenerator, rsaKeyPairGenerator, passwordStrengthAnalyser], }, { name: 'Converter', From b1341852e5526d32d083dcb7571739c168d54b0c Mon Sep 17 00:00:00 2001 From: marvin-j97 <33938500+marvin-j97@users.noreply.github.com> Date: Fri, 14 Jul 2023 01:56:13 +0200 Subject: [PATCH 2/5] style: lint fix --- src/tools/file-hash/file-hash.e2e.spec.ts | 4 +- src/tools/file-hash/file-hash.service.test.ts | 3 +- src/tools/file-hash/file-hash.vue | 163 +++++++++--------- 3 files changed, 87 insertions(+), 83 deletions(-) diff --git a/src/tools/file-hash/file-hash.e2e.spec.ts b/src/tools/file-hash/file-hash.e2e.spec.ts index c44b7c91..7325791f 100644 --- a/src/tools/file-hash/file-hash.e2e.spec.ts +++ b/src/tools/file-hash/file-hash.e2e.spec.ts @@ -1,4 +1,4 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; test.describe('Tool - File hash', () => { test.beforeEach(async ({ page }) => { @@ -12,4 +12,4 @@ test.describe('Tool - File hash', () => { test('', async ({ page }) => { }); -}); \ No newline at end of file +}); diff --git a/src/tools/file-hash/file-hash.service.test.ts b/src/tools/file-hash/file-hash.service.test.ts index cf56c670..aac990d5 100644 --- a/src/tools/file-hash/file-hash.service.test.ts +++ b/src/tools/file-hash/file-hash.service.test.ts @@ -1,6 +1,5 @@ -import { expect, describe, it } from 'vitest'; // import { } from './file-hash.service'; // // describe('file-hash', () => { // -// }) \ No newline at end of file +// }) diff --git a/src/tools/file-hash/file-hash.vue b/src/tools/file-hash/file-hash.vue index 23eac902..fb48e84b 100644 --- a/src/tools/file-hash/file-hash.vue +++ b/src/tools/file-hash/file-hash.vue @@ -1,83 +1,20 @@ - - - - - - - - - Click or drag a file to this area to upload - - - - - - - - - - - - - - - - - - - Copy - - - - - + + + + + + + + + + Click or drag a file to this area to upload + + + + + + + + + + + + + + + + + + + Copy + + + + From 521f939d7e0cc972d582bd10af74629d9d0fcb16 Mon Sep 17 00:00:00 2001 From: marvin-j97 <33938500+marvin-j97@users.noreply.github.com> Date: Fri, 14 Jul 2023 02:05:20 +0200 Subject: [PATCH 3/5] fix(file hash): hash types --- src/tools/file-hash/file-hash.vue | 58 ++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/src/tools/file-hash/file-hash.vue b/src/tools/file-hash/file-hash.vue index fb48e84b..92e74b1e 100644 --- a/src/tools/file-hash/file-hash.vue +++ b/src/tools/file-hash/file-hash.vue @@ -5,7 +5,16 @@ import { Upload } from '@vicons/tabler'; import CryptoJS from 'crypto-js'; import { useCopy } from '@/composable/copy'; -type Hasher = 'md5'; +type Hasher = 'md5' | +'sha1' | +'sha2_224' | +'sha2_256' | +'sha2_384' | +'sha2_512' | +'sha3_224' | +'sha3_256' | +'sha3_384' | +'sha3_512'; type Digest = 'base64' | 'hex'; function useFileHash(target: Ref, hasher: Ref, digest: Ref) { @@ -49,12 +58,17 @@ function readAndHashFile(file: File, hashType: Hasher, digestType: Digest) { fr.onload = (ev) => { const content = ev.target!.result as string; - const hasher = { + const hasher: Record = { md5: CryptoJS.MD5, sha1: CryptoJS.SHA1, - sha256: CryptoJS.SHA256, - sha512: CryptoJS.SHA512, - sha3: CryptoJS.SHA3, + sha2_224: CryptoJS.SHA224, + sha2_256: CryptoJS.SHA256, + sha2_384: CryptoJS.SHA384, + sha2_512: CryptoJS.SHA512, + sha3_224: () => CryptoJS.SHA3(content, { outputLength: 224 }), + sha3_256: () => CryptoJS.SHA3(content, { outputLength: 256 }), + sha3_384: () => CryptoJS.SHA3(content, { outputLength: 384 }), + sha3_512: () => CryptoJS.SHA3(content, { outputLength: 512 }), }; const digest = { @@ -107,20 +121,40 @@ async function onUpload({ file: { file } }: { file: UploadFileInfo }) { value: 'md5', }, { - label: 'SHA-1', + label: 'SHA1', value: 'sha1', }, { - label: 'SHA-256', - value: 'sha256', + label: 'SHA2-224', + value: 'sha2_224', }, { - label: 'SHA-512', - value: 'sha512', + label: 'SHA2-256', + value: 'sha2_256', }, { - label: 'SHA-3', - value: 'sha3', + label: 'SHA2-384', + value: 'sha2_384', + }, + { + label: 'SHA2-512', + value: 'sha2_512', + }, + { + label: 'SHA3-224', + value: 'sha3_224', + }, + { + label: 'SHA3-256', + value: 'sha3_256', + }, + { + label: 'SHA3-384', + value: 'sha3_384', + }, + { + label: 'SHA3-512', + value: 'sha3_512', }, ]" /> From cd3e8eba045a890c294c7b99e99547047e7d57e2 Mon Sep 17 00:00:00 2001 From: marvin-j97 <33938500+marvin-j97@users.noreply.github.com> Date: Fri, 14 Jul 2023 02:08:05 +0200 Subject: [PATCH 4/5] test(file hash): remove test files --- src/tools/file-hash/file-hash.e2e.spec.ts | 15 --------------- src/tools/file-hash/file-hash.service.test.ts | 5 ----- 2 files changed, 20 deletions(-) delete mode 100644 src/tools/file-hash/file-hash.e2e.spec.ts delete mode 100644 src/tools/file-hash/file-hash.service.test.ts diff --git a/src/tools/file-hash/file-hash.e2e.spec.ts b/src/tools/file-hash/file-hash.e2e.spec.ts deleted file mode 100644 index 7325791f..00000000 --- a/src/tools/file-hash/file-hash.e2e.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { expect, test } from '@playwright/test'; - -test.describe('Tool - File hash', () => { - test.beforeEach(async ({ page }) => { - await page.goto('/file-hash'); - }); - - test('Has correct title', async ({ page }) => { - await expect(page).toHaveTitle('File hash - IT Tools'); - }); - - test('', async ({ page }) => { - - }); -}); diff --git a/src/tools/file-hash/file-hash.service.test.ts b/src/tools/file-hash/file-hash.service.test.ts deleted file mode 100644 index aac990d5..00000000 --- a/src/tools/file-hash/file-hash.service.test.ts +++ /dev/null @@ -1,5 +0,0 @@ -// import { } from './file-hash.service'; -// -// describe('file-hash', () => { -// -// }) From f8b65bbbb6d513d16c74c418f571128c3570c10e Mon Sep 17 00:00:00 2001 From: marvin-j97 <33938500+marvin-j97@users.noreply.github.com> Date: Fri, 14 Jul 2023 02:13:01 +0200 Subject: [PATCH 5/5] fix(file hash): remove service file --- src/tools/file-hash/file-hash.service.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/tools/file-hash/file-hash.service.ts diff --git a/src/tools/file-hash/file-hash.service.ts b/src/tools/file-hash/file-hash.service.ts deleted file mode 100644 index e69de29b..00000000