Skip to content

Commit dc9ea1f

Browse files
authored
Merge pull request #33 from CodeDead/feature/upgrades
Feature/upgrades
2 parents b11d361 + be51478 commit dc9ea1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+400
-256
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ This library is maintained by CodeDead. You can find more about us using the fol
3131
* [Twitter](https://twitter.com/C0DEDEAD)
3232
* [Facebook](https://facebook.com/deadlinecodedead)
3333

34-
Copyright © 2022 CodeDead
34+
Copyright © 2023 CodeDead

app/build.gradle

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 31
5-
buildToolsVersion '30.0.3'
4+
compileSdk 34
65
defaultConfig {
76
applicationId "com.codedead.deadhash"
8-
minSdkVersion 24
9-
targetSdkVersion 31
10-
versionName '1.7.8'
7+
minSdk 28
8+
targetSdk 34
9+
versionName '1.8.0'
1110
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12-
versionCode 9
11+
versionCode 10
1312
}
1413
buildTypes {
1514
release {
@@ -20,20 +19,21 @@ android {
2019
productFlavors {
2120
}
2221
compileOptions {
23-
sourceCompatibility JavaVersion.VERSION_1_8
24-
targetCompatibility JavaVersion.VERSION_1_8
22+
sourceCompatibility JavaVersion.VERSION_17
23+
targetCompatibility JavaVersion.VERSION_17
2524
}
25+
namespace 'com.codedead.deadhash'
2626
}
2727

2828
dependencies {
2929
implementation fileTree(include: ['*.jar'], dir: 'libs')
30-
androidTestImplementation('androidx.test.espresso:espresso-core:3.4.0', {
30+
androidTestImplementation('androidx.test.espresso:espresso-core:3.5.1', {
3131
exclude group: 'com.android.support', module: 'support-annotations'
3232
})
33-
implementation 'androidx.appcompat:appcompat:1.4.1'
34-
implementation 'com.google.android.material:material:1.5.0'
35-
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
33+
implementation 'androidx.appcompat:appcompat:1.6.1'
34+
implementation 'com.google.android.material:material:1.10.0'
35+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
3636
implementation 'androidx.cardview:cardview:1.0.0'
37-
implementation "androidx.preference:preference:1.2.0"
37+
implementation 'androidx.preference:preference:1.2.1'
3838
testImplementation 'junit:junit:4.13.2'
3939
}

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
4-
package="com.codedead.deadhash">
3+
xmlns:tools="http://schemas.android.com/tools">
54

6-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
5+
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
6+
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
7+
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
78

89
<application
910
android:name=".main.Runner"
-1.26 KB
Loading

app/src/main/ic_launcher-web.png

-13.7 KB
Binary file not shown.
-22.5 KB
Binary file not shown.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.codedead.deadhash.domain.objects.hashgenerator;
2+
3+
import android.content.ContentResolver;
4+
import android.net.Uri;
5+
6+
import com.codedead.deadhash.domain.utils.HashUtil;
7+
8+
import java.util.List;
9+
10+
public final class FileHashGenerator extends HashGenerator {
11+
12+
private final Uri uri;
13+
private final ContentResolver contentResolver;
14+
15+
/**
16+
* Initialize a new HashGenerator
17+
*
18+
* @param uri The Uri of the file that should be hashed
19+
* @param hashAlgorithms The List of HashingAlgorithm enums that should be used to calculate hashes
20+
* @param compare The compare String for the calculated hashes
21+
*/
22+
public FileHashGenerator(final Uri uri, final ContentResolver contentResolver, final List<HashAlgorithm> hashAlgorithms, final String compare) {
23+
super(hashAlgorithms, compare);
24+
25+
if (uri == null)
26+
throw new NullPointerException("File cannot be null!");
27+
if (contentResolver == null)
28+
throw new NullPointerException("ContentResolver cannot be null!");
29+
30+
this.uri = uri;
31+
this.contentResolver = contentResolver;
32+
}
33+
34+
/**
35+
* Generate the List of HashData for the given input data
36+
*
37+
* @return The List of HashData for the given input data
38+
*/
39+
@Override
40+
public List<HashData> generateHashes() {
41+
for (final HashAlgorithm algorithm : super.getHashAlgorithms()) {
42+
switch (algorithm) {
43+
case md5 -> {
44+
final String md5 = HashUtil.calculateHash(uri, contentResolver, "MD5");
45+
getHashData().add(new HashData("MD5", md5, getCompare()));
46+
}
47+
case sha1 -> {
48+
final String sha1 = HashUtil.calculateHash(uri, contentResolver, "SHA-1");
49+
getHashData().add(new HashData("SHA-1", sha1, getCompare()));
50+
}
51+
case sha224 -> {
52+
final String sha224 = HashUtil.calculateHash(uri, contentResolver, "SHA-224");
53+
getHashData().add(new HashData("SHA-224", sha224, getCompare()));
54+
}
55+
case sha256 -> {
56+
final String sha256 = HashUtil.calculateHash(uri, contentResolver, "SHA-256");
57+
getHashData().add(new HashData("SHA-256", sha256, getCompare()));
58+
}
59+
case sha384 -> {
60+
final String sha384 = HashUtil.calculateHash(uri, contentResolver, "SHA-384");
61+
getHashData().add(new HashData("SHA-384", sha384, getCompare()));
62+
}
63+
case sha512 -> {
64+
final String sha512 = HashUtil.calculateHash(uri, contentResolver, "SHA-512");
65+
getHashData().add(new HashData("SHA-512", sha512, getCompare()));
66+
}
67+
case crc32 -> {
68+
final String crc32 = HashUtil.calculateCRC32(uri, contentResolver);
69+
getHashData().add(new HashData("CRC32", crc32, getCompare()));
70+
}
71+
}
72+
}
73+
74+
return getHashData();
75+
}
76+
}

app/src/main/java/com/codedead/deadhash/domain/objects/hashgenerator/HashData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class HashData implements Parcelable {
1010

1111
private final String compareCheck;
1212

13-
public static final Creator<HashData> CREATOR = new Creator<HashData>() {
13+
public static final Creator<HashData> CREATOR = new Creator<>() {
1414
@Override
1515
public HashData createFromParcel(final Parcel in) {
1616
return new HashData(in);
Lines changed: 15 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,49 @@
11
package com.codedead.deadhash.domain.objects.hashgenerator;
22

3-
import com.codedead.deadhash.domain.utils.HashUtil;
4-
5-
import java.io.File;
6-
import java.io.FileInputStream;
7-
import java.io.IOException;
83
import java.util.ArrayList;
94
import java.util.List;
105

11-
public final class HashGenerator {
12-
13-
private final byte[] data;
6+
public abstract class HashGenerator implements IHashGenerator {
147
private final List<HashAlgorithm> hashAlgorithms;
158
private final List<HashData> hashData;
169
private final String compare;
1710

1811
/**
1912
* Initialize a new HashGenerator
2013
*
21-
* @param data The byte array that should be hashed
2214
* @param hashAlgorithms The List of HashingAlgorithm enums that should be used to calculate hashes
2315
* @param compare The compare String for the calculated hashes
2416
*/
25-
public HashGenerator(final byte[] data, final List<HashAlgorithm> hashAlgorithms, final String compare) {
17+
public HashGenerator(final List<HashAlgorithm> hashAlgorithms, final String compare) {
2618
hashData = new ArrayList<>();
27-
this.data = data;
28-
2919
this.hashAlgorithms = hashAlgorithms;
3020
this.compare = compare;
3121
}
3222

3323
/**
34-
* Initialize a new HashGenerator
24+
* Get the List of HashData for the given input data
3525
*
36-
* @param data The byte array that should be hashed
37-
* @param hashAlgorithms The List of HashingAlgorithm enums that should be used to calculate hashes
38-
* @param compare The compare String for the calculated hashes
39-
* @throws IOException When the File could not be read
26+
* @return The List of HashData for the given input data
4027
*/
41-
public HashGenerator(final File data, final List<HashAlgorithm> hashAlgorithms, final String compare) throws IOException {
42-
hashData = new ArrayList<>();
43-
this.data = readFileToBytes(data);
44-
this.hashAlgorithms = hashAlgorithms;
45-
this.compare = compare;
28+
public List<HashAlgorithm> getHashAlgorithms() {
29+
return hashAlgorithms;
4630
}
4731

4832
/**
49-
* Read a file and return a byte array that represents the given File
33+
* Get the List of HashData for the given input data
5034
*
51-
* @param file The File that should be read
52-
* @return The byte array that represents the given File
53-
* @throws IOException When the File could not be read
35+
* @return The List of HashData for the given input data
5436
*/
55-
private byte[] readFileToBytes(final File file) throws IOException {
56-
if (file == null)
57-
throw new NullPointerException("File cannot be null!");
58-
59-
final int size = (int) file.length();
60-
final byte[] bytes = new byte[size];
61-
final byte[] tmpBuff = new byte[size];
62-
try (final FileInputStream fis = new FileInputStream(file)) {
63-
int read = fis.read(bytes, 0, size);
64-
if (read < size) {
65-
int remain = size - read;
66-
while (remain > 0) {
67-
read = fis.read(tmpBuff, 0, remain);
68-
System.arraycopy(tmpBuff, 0, bytes, size - remain, read);
69-
remain -= read;
70-
}
71-
}
72-
}
73-
74-
return bytes;
37+
public List<HashData> getHashData() {
38+
return hashData;
7539
}
7640

7741
/**
78-
* Generate the List of HashData for the given input data
79-
* @return The List of HashData for the given input data
42+
* Get the compare String for the calculated hashes
43+
*
44+
* @return The compare String for the calculated hashes
8045
*/
81-
public final List<HashData> generateHashes() {
82-
for (final HashAlgorithm algorithm : hashAlgorithms) {
83-
switch (algorithm) {
84-
case md5:
85-
final String md5 = HashUtil.calculateHash(data, "MD5");
86-
hashData.add(new HashData("MD5", md5, compare));
87-
break;
88-
case sha1:
89-
final String sha1 = HashUtil.calculateHash(data, "SHA-1");
90-
hashData.add(new HashData("SHA-1", sha1, compare));
91-
break;
92-
case sha224:
93-
final String sha224 = HashUtil.calculateHash(data, "SHA-224");
94-
hashData.add(new HashData("SHA-224", sha224, compare));
95-
break;
96-
case sha256:
97-
final String sha256 = HashUtil.calculateHash(data, "SHA-256");
98-
hashData.add(new HashData("SHA-256", sha256, compare));
99-
break;
100-
case sha384:
101-
final String sha384 = HashUtil.calculateHash(data, "SHA-384");
102-
hashData.add(new HashData("SHA-384", sha384, compare));
103-
break;
104-
case sha512:
105-
final String sha512 = HashUtil.calculateHash(data, "SHA-512");
106-
hashData.add(new HashData("SHA-512", sha512, compare));
107-
break;
108-
case crc32:
109-
final String crc32 = HashUtil.calculateCRC32(data);
110-
hashData.add(new HashData("CRC32", crc32, compare));
111-
break;
112-
}
113-
}
114-
115-
return hashData;
46+
public String getCompare() {
47+
return compare;
11648
}
11749
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedead.deadhash.domain.objects.hashgenerator;
2+
3+
import java.util.List;
4+
5+
public interface IHashGenerator {
6+
List<HashData> generateHashes();
7+
}

0 commit comments

Comments
 (0)