+ support SHA-256 checksums

This commit is contained in:
Reinhard Pointner 2014-07-22 07:13:35 +00:00
parent 0415ceb37a
commit c0a59b3356
2 changed files with 54 additions and 40 deletions

View File

@ -1,13 +1,10 @@
package net.filebot.hash; package net.filebot.hash;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import net.filebot.MediaTypes; import net.filebot.MediaTypes;
import net.filebot.util.FileUtilities.ExtensionFileFilter; import net.filebot.util.FileUtilities.ExtensionFileFilter;
public enum HashType { public enum HashType {
SFV { SFV {
@ -17,14 +14,12 @@ public enum HashType {
return new ChecksumHash(new CRC32()); return new ChecksumHash(new CRC32());
} }
@Override @Override
public VerificationFormat getFormat() { public VerificationFormat getFormat() {
// e.g folder/file.txt 970E4EF1 // e.g folder/file.txt 970E4EF1
return new SfvFormat(); return new SfvFormat();
} }
@Override @Override
public ExtensionFileFilter getFilter() { public ExtensionFileFilter getFilter() {
return MediaTypes.getDefaultFilter("verification/sfv"); return MediaTypes.getDefaultFilter("verification/sfv");
@ -39,14 +34,12 @@ public enum HashType {
return new MessageDigestHash("MD5"); return new MessageDigestHash("MD5");
} }
@Override @Override
public VerificationFormat getFormat() { public VerificationFormat getFormat() {
// e.g. 50e85fe18e17e3616774637a82968f4c *folder/file.txt // e.g. 50e85fe18e17e3616774637a82968f4c *folder/file.txt
return new VerificationFormat(); return new VerificationFormat();
} }
@Override @Override
public ExtensionFileFilter getFilter() { public ExtensionFileFilter getFilter() {
return MediaTypes.getDefaultFilter("verification/md5sum"); return MediaTypes.getDefaultFilter("verification/md5sum");
@ -61,20 +54,17 @@ public enum HashType {
return new MessageDigestHash("SHA-1"); return new MessageDigestHash("SHA-1");
} }
@Override @Override
public VerificationFormat getFormat() { public VerificationFormat getFormat() {
// e.g 1a02a7c1e9ac91346d08829d5037b240f42ded07 ?SHA1*folder/file.txt // e.g 1a02a7c1e9ac91346d08829d5037b240f42ded07 ?SHA1*folder/file.txt
return new VerificationFormat("SHA1"); return new VerificationFormat("SHA1");
} }
@Override @Override
public ExtensionFileFilter getFilter() { public ExtensionFileFilter getFilter() {
return MediaTypes.getDefaultFilter("verification/sha1sum"); return MediaTypes.getDefaultFilter("verification/sha1sum");
} }
@Override @Override
public String toString() { public String toString() {
return "SHA-1"; return "SHA-1";
@ -82,6 +72,31 @@ public enum HashType {
}, },
SHA256 {
@Override
public Hash newHash() {
return new MessageDigestHash("SHA-256");
}
@Override
public VerificationFormat getFormat() {
// e.g 1a02a7c1e9ac91346d08829d5037b240f42ded07 ?SHA1*folder/file.txt
return new VerificationFormat("SHA256");
}
@Override
public ExtensionFileFilter getFilter() {
return MediaTypes.getDefaultFilter("verification/sha256sum");
}
@Override
public String toString() {
return "SHA-2";
}
},
ED2K { ED2K {
@Override @Override
@ -89,19 +104,16 @@ public enum HashType {
return new Ed2kHash(); return new Ed2kHash();
} }
@Override @Override
public VerificationFormat getFormat() { public VerificationFormat getFormat() {
return new VerificationFormat(); return new VerificationFormat();
} }
@Override @Override
public ExtensionFileFilter getFilter() { public ExtensionFileFilter getFilter() {
return MediaTypes.getDefaultFilter("verification/ed2k"); return MediaTypes.getDefaultFilter("verification/ed2k");
} }
@Override @Override
public String toString() { public String toString() {
return "ED2K"; return "ED2K";
@ -110,10 +122,8 @@ public enum HashType {
public abstract Hash newHash(); public abstract Hash newHash();
public abstract VerificationFormat getFormat(); public abstract VerificationFormat getFormat();
public abstract ExtensionFileFilter getFilter(); public abstract ExtensionFileFilter getFilter();
} }

View File

@ -25,6 +25,10 @@
<extension>sha1</extension> <extension>sha1</extension>
<extension>sha</extension> <extension>sha</extension>
</type> </type>
<type name="verification/sha256sum">
<extension>sha256</extension>
<extension>sha2</extension>
</type>
<type name="verification/ed2k"> <type name="verification/ed2k">
<extension>ed2k</extension> <extension>ed2k</extension>
</type> </type>