Skip to content

Commit e8c01cc

Browse files
authored
Merge pull request #44 from CodeDead/feature/crc
feature/crc
2 parents 151dbde + 4231a1b commit e8c01cc

File tree

21 files changed

+278
-19
lines changed

21 files changed

+278
-19
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
},
7272
"devDependencies": {
7373
"concurrently": "^5.3.0",
74-
"electron": "^11.2.2",
74+
"electron": "^11.2.3",
7575
"electron-builder": "^22.9.1",
7676
"eslint": "^7.19.0",
7777
"eslint-config-airbnb": "^18.2.1",

public/workers/FileWorker/index.html

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
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;
12+
const crcCalculator = require('crc');
1313

14-
const fileHash = (filePath, md4, md5, sha1, sha224, sha256, sha384, sha512, ripemd160, crc32) => {
14+
const fileHash = (
15+
filePath, md4, md5, sha1, sha224, sha256, sha384, sha512, ripemd160,
16+
crc1, crc8, crc16, crc24, crc32,
17+
) => {
1518
return new Promise((resolve, reject) => {
1619
let MD4,
1720
MD5,
@@ -21,7 +24,11 @@
2124
SHA384,
2225
SHA512,
2326
RIPEMD160,
24-
crc32Checksum;
27+
crc1Checksum,
28+
crc8Checksum,
29+
crc16Checksum,
30+
crc24Checksum,
31+
crc32Checksum;
2532

2633
if (md4) MD4 = crypto.createHash('md4');
2734
if (md5) MD5 = crypto.createHash('md5');
@@ -32,7 +39,6 @@
3239
if (sha512) SHA512 = crypto.createHash('sha512');
3340
if (ripemd160) RIPEMD160 = crypto.createHash('ripemd160');
3441

35-
3642
try {
3743
const s = fs.createReadStream(filePath.toString());
3844

@@ -45,7 +51,11 @@
4551
if (sha384) SHA384.update(data);
4652
if (sha512) SHA512.update(data);
4753
if (ripemd160) RIPEMD160.update(data);
48-
if (crc32) crc32Checksum = crc32Calculator(data, crc32Checksum);
54+
if (crc1) crc1Checksum = crcCalculator.crc1(data, crc1Checksum);
55+
if (crc8) crc8Checksum = crcCalculator.crc8(data, crc8Checksum);
56+
if (crc16) crc16Checksum = crcCalculator.crc16(data, crc16Checksum);
57+
if (crc24) crc24Checksum = crcCalculator.crc24(data, crc24Checksum);
58+
if (crc32) crc32Checksum = crcCalculator.crc32(data, crc32Checksum);
4959
});
5060

5161
s.on('end', () => {
@@ -107,6 +117,30 @@
107117
.toString()
108118
});
109119
}
120+
if (crc1) {
121+
newHashes.push({
122+
type: 'CRC1',
123+
hash: crc1Checksum.toString(16),
124+
});
125+
}
126+
if (crc8) {
127+
newHashes.push({
128+
type: 'CRC8',
129+
hash: crc8Checksum.toString(16),
130+
});
131+
}
132+
if (crc16) {
133+
newHashes.push({
134+
type: 'CRC16',
135+
hash: crc16Checksum.toString(16),
136+
});
137+
}
138+
if (crc24) {
139+
newHashes.push({
140+
type: 'CRC24',
141+
hash: crc24Checksum.toString(16),
142+
});
143+
}
110144
if (crc32) {
111145
newHashes.push({
112146
type: 'CRC32',
@@ -120,7 +154,6 @@
120154
});
121155

122156
s.on('error', error => {
123-
124157
return reject(error);
125158
});
126159
} catch (error) {
@@ -130,7 +163,10 @@
130163
}
131164

132165
ipcRenderer.on("calculate-file-hash", (e, data) => {
133-
fileHash(data.filePath, data.md4, data.md5, data.sha1, data.sha224, data.sha256, data.sha384, data.sha512, data.ripemd160, data.crc32)
166+
fileHash(
167+
data.filePath, data.md4, data.md5, data.sha1, data.sha224, data.sha256, data.sha384, data.sha512,
168+
data.ripemd160, data.crc1, data.crc8, data.crc16, data.crc24, data.crc32,
169+
)
134170
.then(data => {
135171
ipcRenderer.send("file-hash-calculated", data);
136172
})

public/workers/TextWorker/index.html

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
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, crc32) => {
12+
const textHash = (
13+
text, md4, md5, sha1, sha224, sha256, sha384, sha512, ripemd160,
14+
crc1, crc8, crc16, crc24, crc32,
15+
) => {
1316
return new Promise((resolve, reject) => {
1417
let newHashes = [];
1518
try {
@@ -85,6 +88,34 @@
8588
.toString()
8689
});
8790
}
91+
if (crc1) {
92+
const { crc1 } = require('crc');
93+
newHashes.push({
94+
type: 'CRC1',
95+
hash: crc1(text).toString(16),
96+
});
97+
}
98+
if (crc8) {
99+
const { crc8 } = require('crc');
100+
newHashes.push({
101+
type: 'CRC8',
102+
hash: crc8(text).toString(16),
103+
});
104+
}
105+
if (crc16) {
106+
const { crc16 } = require('crc');
107+
newHashes.push({
108+
type: 'CRC16',
109+
hash: crc16(text).toString(16),
110+
});
111+
}
112+
if (crc24) {
113+
const { crc24 } = require('crc');
114+
newHashes.push({
115+
type: 'CRC24',
116+
hash: crc24(text).toString(16),
117+
});
118+
}
88119
if (crc32) {
89120
const { crc32 } = require('crc');
90121
newHashes.push({
@@ -103,7 +134,10 @@
103134
};
104135

105136
ipcRenderer.on('calculate-text-hash', (e, data) => {
106-
textHash(data.text, data.md4, data.md5, data.sha1, data.sha224, data.sha256, data.sha384, data.sha512, data.ripemd160, data.crc32)
137+
textHash(
138+
data.text, data.md4, data.md5, data.sha1, data.sha224, data.sha256, data.sha384, data.sha512, data.ripemd160,
139+
data.crc1, data.crc8, data.crc16, data.crc24, data.crc32,
140+
)
107141
.then(data => {
108142
ipcRenderer.send('text-hash-calculated', data);
109143
})

src/contexts/CryptoContextReducer/index.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ 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 crc1 = !!(localStorage.crc1 && localStorage.crc1 === 'true');
13+
const crc8 = !!(localStorage.crc8 && localStorage.crc8 === 'true');
14+
const crc16 = !!(localStorage.crc16 && localStorage.crc16 === 'true');
15+
const crc24 = !!(localStorage.crc24 && localStorage.crc24 === 'true');
1216
const crc32 = localStorage.crc32 && localStorage.crc32 === 'true' ? true : !localStorage.crc32;
1317

1418
const initState = {
@@ -20,6 +24,10 @@ const initState = {
2024
sha384,
2125
sha512,
2226
ripemd160,
27+
crc1,
28+
crc8,
29+
crc16,
30+
crc24,
2331
crc32,
2432
fileHashes: null,
2533
textHashes: null,

src/languages/de_DE/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const de_DE = () => ({
4040
sha512: 'SHA-512',
4141
ripemd160: 'RIPEMD-160',
4242
sha224: 'SHA-224',
43+
crc1: 'CRC1',
44+
crc8: 'CRC8',
45+
crc16: 'CRC16',
46+
crc24: 'CRC24',
4347
crc32: 'CRC32',
4448
file: 'Datei',
4549
fileSubtitle: 'Berechnen Sie Datei-Hashes',
@@ -82,6 +86,7 @@ const de_DE = () => ({
8286
orange: 'Orange',
8387
orangeThemeDescription: 'Lass uns Niederländisch werden.',
8488
themeToggleEnabled: 'Thema umschalten',
89+
cyclicRedundancyCheck: 'Zyklische Redundanzprüfung',
8590
});
8691

8792
// eslint-disable-next-line camelcase

src/languages/en_US/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const en_US = () => ({
4040
sha512: 'SHA-512',
4141
ripemd160: 'RIPEMD-160',
4242
sha224: 'SHA-224',
43+
crc1: 'CRC1',
44+
crc8: 'CRC8',
45+
crc16: 'CRC16',
46+
crc24: 'CRC24',
4347
crc32: 'CRC32',
4448
file: 'File',
4549
fileSubtitle: 'Calculate file hashes',
@@ -82,6 +86,7 @@ const en_US = () => ({
8286
orange: 'Orange',
8387
orangeThemeDescription: 'Let\'s get Dutch.',
8488
themeToggleEnabled: 'Theme toggle',
89+
cyclicRedundancyCheck: 'Cyclic redundancy check',
8590
});
8691

8792
// eslint-disable-next-line camelcase

src/languages/es_ES/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const es_ES = () => ({
4040
sha512: 'SHA-512',
4141
ripemd160: 'RIPEMD-160',
4242
sha224: 'SHA-224',
43+
crc1: 'CRC1',
44+
crc8: 'CRC8',
45+
crc16: 'CRC16',
46+
crc24: 'CRC24',
4347
crc32: 'CRC32',
4448
file: 'Archivo',
4549
fileSubtitle: 'Calcular hashes de archivos',
@@ -82,6 +86,7 @@ const es_ES = () => ({
8286
orange: 'Naranja',
8387
orangeThemeDescription: 'Vamos a holandeses.',
8488
themeToggleEnabled: 'Alternar tema',
89+
cyclicRedundancyCheck: 'Verificación de redundancia cíclica',
8590
});
8691

8792
// eslint-disable-next-line camelcase

src/languages/fr_FR/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const fr_FR = () => ({
4040
sha512: 'SHA-512',
4141
ripemd160: 'RIPEMD-160',
4242
sha224: 'SHA-224',
43+
crc1: 'CRC1',
44+
crc8: 'CRC8',
45+
crc16: 'CRC16',
46+
crc24: 'CRC24',
4347
crc32: 'CRC32',
4448
file: 'File',
4549
fileSubtitle: 'Calculer les hachages de fichier',
@@ -82,6 +86,7 @@ const fr_FR = () => ({
8286
orange: 'Orange',
8387
orangeThemeDescription: 'Il faut que ça Néerlandais.',
8488
themeToggleEnabled: 'Basculer le thème',
89+
cyclicRedundancyCheck: 'Contrôle de redondance cyclique',
8590
});
8691

8792
// eslint-disable-next-line camelcase

src/languages/it_IT/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const it_IT = () => ({
4040
sha512: 'SHA-512',
4141
ripemd160: 'RIPEMD-160',
4242
sha224: 'SHA-224',
43+
crc1: 'CRC1',
44+
crc8: 'CRC8',
45+
crc16: 'CRC16',
46+
crc24: 'CRC24',
4347
crc32: 'CRC32',
4448
file: 'File',
4549
fileSubtitle: 'Calcola gli hash dei file',
@@ -82,6 +86,7 @@ const it_IT = () => ({
8286
orange: 'Arancia',
8387
orangeThemeDescription: 'Prendiamo l\'olandese.',
8488
themeToggleEnabled: 'Commutazione del tema',
89+
cyclicRedundancyCheck: 'Controllo di ridondanza ciclico',
8590
});
8691

8792
// eslint-disable-next-line camelcase

src/languages/jp_JP/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ const jp_JP = () => ({
4040
sha512: 'SHA-512',
4141
ripemd160: 'RIPEMD-160',
4242
sha224: 'SHA-224',
43+
crc1: 'CRC1',
44+
crc8: 'CRC8',
45+
crc16: 'CRC16',
46+
crc24: 'CRC24',
4347
crc32: 'CRC32',
4448
file: 'ファイル',
4549
fileSubtitle: 'ファイルハッシュの計算',
@@ -82,6 +86,7 @@ const jp_JP = () => ({
8286
orange: 'オレンジ',
8387
orangeThemeDescription: 'オランダ語を取得しましょう。',
8488
themeToggleEnabled: 'テーマの切り替え',
89+
cyclicRedundancyCheck: '巡回冗長検査',
8590
});
8691

8792
// eslint-disable-next-line camelcase

0 commit comments

Comments
 (0)