Skip to content

Commit ddf0a00

Browse files
authored
Merge pull request #35 from CodeDead/feature/crc32
feature/crc32
2 parents 2e9eded + 2516d01 commit ddf0a00

File tree

21 files changed

+241
-9
lines changed

21 files changed

+241
-9
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"dependencies": {
3838
"@material-ui/core": "^4.11.3",
3939
"@material-ui/icons": "^4.11.2",
40+
"crc": "^3.8.0",
4041
"cross-env": "^7.0.3",
4142
"electron-is-dev": "^1.2.0",
4243
"react": "^17.0.1",
@@ -72,6 +73,7 @@
7273
"concurrently": "^5.3.0",
7374
"electron": "^11.2.2",
7475
"electron-builder": "^22.9.1",
76+
"eslint": "^7.19.0",
7577
"eslint-config-airbnb": "^18.2.1",
7678
"eslint-plugin-import": "^2.22.1",
7779
"eslint-plugin-jsx-a11y": "^6.4.1",

public/workers/FileWorker/index.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
const ipcRenderer = window.require('electron').ipcRenderer;
1010
const fs = window.require('fs');
1111
const crypto = window.require('crypto');
12+
const crc32Calculator = require('crc').crc32;
1213

13-
const fileHash = (filePath, md4, md5, sha1, sha224, sha256, sha384, sha512, ripemd160) => {
14+
const fileHash = (filePath, md4, md5, sha1, sha224, sha256, sha384, sha512, ripemd160, crc32) => {
1415
return new Promise((resolve, reject) => {
1516
let MD4,
1617
MD5,
@@ -19,7 +20,8 @@
1920
SHA256,
2021
SHA384,
2122
SHA512,
22-
RIPEMD160;
23+
RIPEMD160,
24+
crc32Checksum;
2325

2426
if (md4) MD4 = crypto.createHash('md4');
2527
if (md5) MD5 = crypto.createHash('md5');
@@ -30,6 +32,7 @@
3032
if (sha512) SHA512 = crypto.createHash('sha512');
3133
if (ripemd160) RIPEMD160 = crypto.createHash('ripemd160');
3234

35+
3336
try {
3437
const s = fs.createReadStream(filePath.toString());
3538

@@ -42,6 +45,7 @@
4245
if (sha384) SHA384.update(data);
4346
if (sha512) SHA512.update(data);
4447
if (ripemd160) RIPEMD160.update(data);
48+
if (crc32) crc32Checksum = crc32Calculator(data, crc32Checksum);
4549
});
4650

4751
s.on('end', () => {
@@ -103,6 +107,12 @@
103107
.toString()
104108
});
105109
}
110+
if (crc32) {
111+
newHashes.push({
112+
type: 'CRC32',
113+
hash: crc32Checksum.toString(16),
114+
});
115+
}
106116

107117
if (newHashes.length === 0) newHashes = null;
108118

@@ -120,7 +130,7 @@
120130
}
121131

122132
ipcRenderer.on("calculate-file-hash", (e, data) => {
123-
fileHash(data.filePath, data.md4, data.md5, data.sha1, data.sha224, data.sha256, data.sha384, data.sha512, data.ripemd160)
133+
fileHash(data.filePath, data.md4, data.md5, data.sha1, data.sha224, data.sha256, data.sha384, data.sha512, data.ripemd160, data.crc32)
124134
.then(data => {
125135
ipcRenderer.send("file-hash-calculated", data);
126136
})

public/workers/TextWorker/index.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
const ipcRenderer = window.require('electron').ipcRenderer;
1010
const crypto = window.require('crypto');
1111

12-
const textHash = (text, md4, md5, sha1, sha224, sha256, sha384, sha512, ripemd160) => {
12+
const textHash = (text, md4, md5, sha1, sha224, sha256, sha384, sha512, ripemd160, crc32) => {
1313
return new Promise((resolve, reject) => {
1414
let newHashes = [];
1515
try {
@@ -85,6 +85,13 @@
8585
.toString()
8686
});
8787
}
88+
if (crc32) {
89+
const { crc32 } = require('crc');
90+
newHashes.push({
91+
type: 'CRC32',
92+
hash: crc32(text).toString(16),
93+
});
94+
}
8895

8996
if (newHashes.length === 0) newHashes = null;
9097

@@ -96,7 +103,7 @@
96103
};
97104

98105
ipcRenderer.on('calculate-text-hash', (e, data) => {
99-
textHash(data.text, data.md4, data.md5, data.sha1, data.sha224, data.sha256, data.sha384, data.sha512, data.ripemd160)
106+
textHash(data.text, data.md4, data.md5, data.sha1, data.sha224, data.sha256, data.sha384, data.sha512, data.ripemd160, data.crc32)
100107
.then(data => {
101108
ipcRenderer.send('text-hash-calculated', data);
102109
})

src/contexts/CryptoContextReducer/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const sha256 = localStorage.sha256 && localStorage.sha256 === 'true' ? true : !l
99
const sha384 = localStorage.sha384 && localStorage.sha384 === 'true' ? true : !localStorage.sha384;
1010
const sha512 = localStorage.sha512 && localStorage.sha512 === 'true' ? true : !localStorage.sha512;
1111
const ripemd160 = localStorage.ripemd160 && localStorage.ripemd160 === 'true' ? true : !localStorage.ripemd160;
12+
const crc32 = localStorage.crc32 && localStorage.crc32 === 'true' ? true : !localStorage.crc32;
1213

1314
const initState = {
1415
md4,
@@ -19,6 +20,7 @@ const initState = {
1920
sha384,
2021
sha512,
2122
ripemd160,
23+
crc32,
2224
fileHashes: null,
2325
textHashes: null,
2426
textInput: '',

src/languages/de_DE/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const de_DE = () => ({
4040
sha512: 'SHA-512',
4141
ripemd160: 'RIPEMD-160',
4242
sha224: 'SHA-224',
43+
crc32: 'CRC32',
4344
file: 'Datei',
4445
fileSubtitle: 'Berechnen Sie Datei-Hashes',
4546
text: 'Text',

src/languages/en_US/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const en_US = () => ({
4040
sha512: 'SHA-512',
4141
ripemd160: 'RIPEMD-160',
4242
sha224: 'SHA-224',
43+
crc32: 'CRC32',
4344
file: 'File',
4445
fileSubtitle: 'Calculate file hashes',
4546
text: 'Text',

src/languages/es_ES/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const es_ES = () => ({
4040
sha512: 'SHA-512',
4141
ripemd160: 'RIPEMD-160',
4242
sha224: 'SHA-224',
43+
crc32: 'CRC32',
4344
file: 'Archivo',
4445
fileSubtitle: 'Calcular hashes de archivos',
4546
text: 'Texto',

src/languages/fr_FR/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const fr_FR = () => ({
4040
sha512: 'SHA-512',
4141
ripemd160: 'RIPEMD-160',
4242
sha224: 'SHA-224',
43+
crc32: 'CRC32',
4344
file: 'File',
4445
fileSubtitle: 'Calculer les hachages de fichier',
4546
text: 'Texte',

src/languages/it_IT/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const it_IT = () => ({
4040
sha512: 'SHA-512',
4141
ripemd160: 'RIPEMD-160',
4242
sha224: 'SHA-224',
43+
crc32: 'CRC32',
4344
file: 'File',
4445
fileSubtitle: 'Calcola gli hash dei file',
4546
text: 'Testo',

src/languages/jp_JP/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const jp_JP = () => ({
4040
sha512: 'SHA-512',
4141
ripemd160: 'RIPEMD-160',
4242
sha224: 'SHA-224',
43+
crc32: 'CRC32',
4344
file: 'ファイル',
4445
fileSubtitle: 'ファイルハッシュの計算',
4546
text: 'テキスト',

0 commit comments

Comments
 (0)