- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
98 lines
3.2 KiB
Java
98 lines
3.2 KiB
Java
package com.mbridge.msdk.thrid.okio;
|
|
|
|
import androidx.annotation.Nullable;
|
|
import com.mbridge.msdk.foundation.tools.SameMD5;
|
|
import com.unity3d.ads.core.data.datasource.AndroidStaticDeviceInfoDataSource;
|
|
import java.io.IOException;
|
|
import java.security.InvalidKeyException;
|
|
import java.security.MessageDigest;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import javax.crypto.Mac;
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public final class HashingSink extends ForwardingSink {
|
|
|
|
@Nullable
|
|
private final Mac mac;
|
|
|
|
@Nullable
|
|
private final MessageDigest messageDigest;
|
|
|
|
public static HashingSink md5(Sink sink) {
|
|
return new HashingSink(sink, SameMD5.TAG);
|
|
}
|
|
|
|
public static HashingSink sha1(Sink sink) {
|
|
return new HashingSink(sink, AndroidStaticDeviceInfoDataSource.ALGORITHM_SHA1);
|
|
}
|
|
|
|
public static HashingSink sha256(Sink sink) {
|
|
return new HashingSink(sink, "SHA-256");
|
|
}
|
|
|
|
public static HashingSink sha512(Sink sink) {
|
|
return new HashingSink(sink, "SHA-512");
|
|
}
|
|
|
|
public static HashingSink hmacSha1(Sink sink, ByteString byteString) {
|
|
return new HashingSink(sink, byteString, "HmacSHA1");
|
|
}
|
|
|
|
public static HashingSink hmacSha256(Sink sink, ByteString byteString) {
|
|
return new HashingSink(sink, byteString, "HmacSHA256");
|
|
}
|
|
|
|
public static HashingSink hmacSha512(Sink sink, ByteString byteString) {
|
|
return new HashingSink(sink, byteString, "HmacSHA512");
|
|
}
|
|
|
|
private HashingSink(Sink sink, String str) {
|
|
super(sink);
|
|
try {
|
|
this.messageDigest = MessageDigest.getInstance(str);
|
|
this.mac = null;
|
|
} catch (NoSuchAlgorithmException unused) {
|
|
throw new AssertionError();
|
|
}
|
|
}
|
|
|
|
private HashingSink(Sink sink, ByteString byteString, String str) {
|
|
super(sink);
|
|
try {
|
|
Mac mac = Mac.getInstance(str);
|
|
this.mac = mac;
|
|
mac.init(new SecretKeySpec(byteString.toByteArray(), str));
|
|
this.messageDigest = null;
|
|
} catch (InvalidKeyException e) {
|
|
throw new IllegalArgumentException(e);
|
|
} catch (NoSuchAlgorithmException unused) {
|
|
throw new AssertionError();
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.thrid.okio.ForwardingSink, com.mbridge.msdk.thrid.okio.Sink
|
|
public void write(Buffer buffer, long j) throws IOException {
|
|
Util.checkOffsetAndCount(buffer.size, 0L, j);
|
|
Segment segment = buffer.head;
|
|
long j2 = 0;
|
|
while (j2 < j) {
|
|
int min = (int) Math.min(j - j2, segment.limit - segment.pos);
|
|
MessageDigest messageDigest = this.messageDigest;
|
|
if (messageDigest != null) {
|
|
messageDigest.update(segment.data, segment.pos, min);
|
|
} else {
|
|
this.mac.update(segment.data, segment.pos, min);
|
|
}
|
|
j2 += min;
|
|
segment = segment.next;
|
|
}
|
|
super.write(buffer, j);
|
|
}
|
|
|
|
public final ByteString hash() {
|
|
MessageDigest messageDigest = this.messageDigest;
|
|
return ByteString.of(messageDigest != null ? messageDigest.digest() : this.mac.doFinal());
|
|
}
|
|
}
|