Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Add support for CRC32 and SHA3 hash #16

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
20 changes: 10 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v1
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.3.0'
- name: Install dependencies
Expand All @@ -22,14 +22,14 @@ jobs:
dart_links_reachable:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/checkout@main
with:
repository: hash-checker/dart_links_reachable
path: './dart_links_reachable'
- uses: dart-lang/setup-dart@v1.0
- uses: dart-lang/setup-dart@v1
with:
sdk: 2.18.0
sdk: 2.19.6
- name: Install dependencies
working-directory: dart_links_reachable
run: dart pub get
Expand All @@ -40,14 +40,14 @@ jobs:
flutter_mobx_structure_validator:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/checkout@main
with:
repository: hash-checker/flutter_mobx_structure_validator
path: './flutter_mobx_structure_validator'
- uses: dart-lang/setup-dart@v1.0
- uses: dart-lang/setup-dart@v1
with:
sdk: 2.18.0
sdk: 2.19.6
- name: Install dependencies
working-directory: flutter_mobx_structure_validator
run: dart pub get
Expand All @@ -58,12 +58,12 @@ jobs:
android_build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/checkout@main
with:
repository: hash-checker/hc2_builder
path: './hc2_builder'
- uses: subosito/flutter-action@v1
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.3.0'
- name: Build Android app
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Original app is still maintaining and will not be archived in near future.

| Name | Since version | Status |
|----------------------------------------------------|---------------|--------------|
| [CRC32](https://en.wikipedia.org/wiki/CRC32) | 1.0.0 | `Supporting` |
| [MD5](https://en.wikipedia.org/wiki/MD5) | 1.0.0 | `Supporting` |
| [SHA-1](https://en.wikipedia.org/wiki/SHA-1) | 1.0.0 | `Supporting` |
| [SHA-224](https://en.wikipedia.org/wiki/SHA-2) | 1.0.0 | `Supporting` |
Expand All @@ -30,6 +31,10 @@ Original app is still maintaining and will not be archived in near future.
| [SHA-512](https://en.wikipedia.org/wiki/SHA-2) | 1.0.0 | `Supporting` |
| [SHA-512/224](https://en.wikipedia.org/wiki/SHA-2) | 1.0.0 | `Supporting` |
| [SHA-512/256](https://en.wikipedia.org/wiki/SHA-2) | 1.0.0 | `Supporting` |
| [SHA3-224](https://en.wikipedia.org/wiki/SHA-3) | 1.0.0 | `Supporting` |
| [SHA3-256](https://en.wikipedia.org/wiki/SHA-3) | 1.0.0 | `Supporting` |
| [SHA3-384](https://en.wikipedia.org/wiki/SHA-3) | 1.0.0 | `Supporting` |
| [SHA3-512](https://en.wikipedia.org/wiki/SHA-3) | 1.0.0 | `Supporting` |

## Languages

Expand Down
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ flutter {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.5.10'
ext.kotlin_version = '1.8.20'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -24,6 +24,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
20 changes: 20 additions & 0 deletions lib/extensions/hash_type_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:hash_checker_2/model/hash_type.dart';
extension HashTypeToString on HashType {
String get uiName {
switch (this) {
case HashType.crc32:
return 'CRC32';
case HashType.md5:
return 'MD5';
case HashType.sha1:
Expand All @@ -19,13 +21,23 @@ extension HashTypeToString on HashType {
return 'SHA-512/224';
case HashType.sha512_256:
return 'SHA-512/256';
case HashType.sha3_224:
return 'SHA3-224';
case HashType.sha3_256:
return 'SHA3-256';
case HashType.sha3_384:
return 'SHA3-384';
case HashType.sha3_512:
return 'SHA3-512';
}
}
}

extension HashTypeToFileExtensionPart on HashType {
String get fileExtensionPart {
switch (this) {
case HashType.crc32:
return 'crc32';
case HashType.md5:
return 'md5';
case HashType.sha1:
Expand All @@ -42,6 +54,14 @@ extension HashTypeToFileExtensionPart on HashType {
return 'sha512_224';
case HashType.sha512_256:
return 'sha512_256';
case HashType.sha3_224:
return 'sha3-224';
case HashType.sha3_256:
return 'sha3-256';
case HashType.sha3_384:
return 'sha3-384';
case HashType.sha3_512:
return 'sha3-512';
}
}
}
5 changes: 5 additions & 0 deletions lib/model/hash_type.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
enum HashType {
crc32,
md5,
sha1,
sha224,
Expand All @@ -7,4 +8,8 @@ enum HashType {
sha512,
sha512_224,
sha512_256,
sha3_224,
sha3_256,
sha3_384,
sha3_512,
}
42 changes: 23 additions & 19 deletions lib/pages/calculator/page/dialogs/select_hash_type_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:hash_checker_2/extensions/hash_type_extensions.dart';
import 'package:hash_checker_2/model/hash_type.dart';
import 'package:hash_checker_2/ui/widgets/app_rounded_bottom_sheet.dart';

Future<HashType?> showSelectHashTypeDialog({
required BuildContext context,
Expand All @@ -11,23 +10,28 @@ Future<HashType?> showSelectHashTypeDialog({
context: context,
backgroundColor: Colors.transparent,
isScrollControlled: true,
builder: (_) {
return AppRoundedBottomSheet(
child: Column(
children: HashType.values.map(
(hashType) {
return ListTile(
title: Text(hashType.uiName),
trailing: hashType == current ? const Icon(Icons.done) : null,
onTap: () => Navigator.pop<HashType>(
context,
hashType,
),
);
},
).toList(),
),
);
},
builder: (context) => DraggableScrollableSheet(
initialChildSize: 0.4,
minChildSize: 0.2,
maxChildSize: 0.75,
expand: false,
builder: (_, controller) => ListView(
controller: controller,
padding: const EdgeInsets.all(8),
children: HashType.values.map(
(hashType) {
return ListTile(
tileColor: Colors.white,
title: Text(hashType.uiName),
trailing: hashType == current ? const Icon(Icons.done) : null,
onTap: () => Navigator.pop<HashType>(
context,
hashType,
),
);
},
).toList(),
),
),
);
}
34 changes: 27 additions & 7 deletions lib/pages/calculator/store/calculator_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:crypto/crypto.dart';
import 'package:hash_checker_2/extensions/hash_type_extensions.dart';
import 'package:hash_checker_2/model/hash_compare_result.dart';
import 'package:hash_checker_2/model/hash_source.dart';
import 'package:hash_checker_2/model/hash_type.dart';
import 'package:hashlib/hashlib.dart';
import 'package:mobx/mobx.dart';

part 'calculator_store.g.dart';
Expand Down Expand Up @@ -41,19 +41,24 @@ abstract class _CalculatorStore with Store {
? fileToGenerate
: textValueToGenerate;

HashCompareResult compare() => originalHash == generatedHash ? HashCompareResult.match : HashCompareResult.doNotMatch;
HashCompareResult compare() => originalHash == generatedHash
? HashCompareResult.match
: HashCompareResult.doNotMatch;

bool get canSaveGeneratedHashResult => hashSource != HashSource.none;

Uint8List get generatedHashToFile => Uint8List.fromList(utf8.encode(generatedHash));
Uint8List get generatedHashToFile =>
Uint8List.fromList(utf8.encode(generatedHash));

String get fileNameForGeneratedHash => '$source.${hashType.fileExtensionPart}.txt';
String get fileNameForGeneratedHash =>
'$source.${hashType.fileExtensionPart}.txt';

@action
void setOriginalHash(String originalHash) => this.originalHash = originalHash;

@action
void setGeneratedHash(String generatedHash) => this.generatedHash = generatedHash;
void setGeneratedHash(String generatedHash) =>
this.generatedHash = generatedHash;

@action
void setHashType(HashType hashType) => this.hashType = hashType;
Expand Down Expand Up @@ -87,6 +92,9 @@ abstract class _CalculatorStore with Store {
}
if (bytes != null) {
switch (hashType) {
case HashType.crc32:
generatedHash = crc32.convert(bytes).toString();
break;
case HashType.md5:
generatedHash = md5.convert(bytes).toString();
break;
Expand All @@ -106,10 +114,22 @@ abstract class _CalculatorStore with Store {
generatedHash = sha512.convert(bytes).toString();
break;
case HashType.sha512_224:
generatedHash = sha512224.convert(bytes).toString();
generatedHash = sha512t224.convert(bytes).toString();
break;
case HashType.sha512_256:
generatedHash = sha512256.convert(bytes).toString();
generatedHash = sha512t256.convert(bytes).toString();
break;
case HashType.sha3_224:
generatedHash = sha3_224.convert(bytes).toString();
break;
case HashType.sha3_256:
generatedHash = sha3_256.convert(bytes).toString();
break;
case HashType.sha3_384:
generatedHash = sha3_384.convert(bytes).toString();
break;
case HashType.sha3_512:
generatedHash = sha3_512.convert(bytes).toString();
break;
}
}
Expand Down
Loading
Loading