Merge pull request #513 from TeamPiped/hash-sha256

Cleanup unnecessary hash function.
This commit is contained in:
Kavin 2023-01-30 16:58:53 +00:00 committed by GitHub
commit 78766d4360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 20 deletions

View File

@ -7,11 +7,10 @@ import com.grack.nanojson.JsonWriter;
import me.kavin.piped.consts.Constants;
import me.kavin.piped.utils.resp.InvalidRequestResponse;
import me.kavin.piped.utils.resp.SimpleErrorMessage;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class SponsorBlockUtils {
@ -22,7 +21,7 @@ public class SponsorBlockUtils {
if (StringUtils.isEmpty(categories))
return Constants.mapper.writeValueAsString(new InvalidRequestResponse());
String hash = toSha256(id);
String hash = DigestUtils.sha256Hex(id);
for (String url : Constants.SPONSORBLOCK_SERVERS) {
try {
@ -46,21 +45,4 @@ public class SponsorBlockUtils {
return null;
}
private static String toSha256(final String videoId) throws NoSuchAlgorithmException {
final MessageDigest digest = MessageDigest.getInstance("SHA-256");
final byte[] bytes = digest.digest(videoId.getBytes(StandardCharsets.UTF_8));
final StringBuilder sb = new StringBuilder();
for (final byte b : bytes) {
final String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex);
}
return sb.toString();
}
}