mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-02-05 12:42:34 -05:00
Merge branch 'digestinputstream' into 'master'
There's an official DigestInputStream, no need to make our own See merge request fdroid/fdroidclient!1456
This commit is contained in:
@@ -7,7 +7,7 @@ import org.fdroid.download.DownloadRequest
|
||||
import org.fdroid.download.DownloaderFactory
|
||||
import org.fdroid.download.HttpManager
|
||||
import org.fdroid.download.getDigestInputStream
|
||||
import org.fdroid.fdroid.DigestInputStream
|
||||
import org.fdroid.fdroid.getDigestHex
|
||||
import org.fdroid.index.IndexParser
|
||||
import org.fdroid.index.RepoUriBuilder
|
||||
import org.fdroid.index.SigningException
|
||||
@@ -18,6 +18,7 @@ import org.fdroid.index.v2.FileV2
|
||||
import org.fdroid.index.v2.IndexV2FullStreamProcessor
|
||||
import org.fdroid.index.v2.SIGNED_FILE_NAME
|
||||
import java.net.Proxy
|
||||
import java.security.DigestInputStream
|
||||
import java.security.MessageDigest
|
||||
|
||||
internal class RepoV2Fetcher(
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.fdroid.download.DownloaderFactory
|
||||
import org.fdroid.download.HttpManager
|
||||
import org.fdroid.download.NotFoundException
|
||||
import org.fdroid.download.getDigestInputStream
|
||||
import org.fdroid.fdroid.DigestInputStream
|
||||
import org.fdroid.index.IndexFormatVersion
|
||||
import org.fdroid.index.IndexParser.json
|
||||
import org.fdroid.index.SigningException
|
||||
@@ -55,6 +54,7 @@ import org.junit.rules.TemporaryFolder
|
||||
import org.junit.runner.RunWith
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.IOException
|
||||
import java.security.DigestInputStream
|
||||
import java.security.MessageDigest
|
||||
import java.util.concurrent.Callable
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -10,9 +10,9 @@ import okhttp3.ConnectionSpec.Companion.MODERN_TLS
|
||||
import okhttp3.ConnectionSpec.Companion.RESTRICTED_TLS
|
||||
import okhttp3.Dns
|
||||
import okhttp3.internal.tls.OkHostnameVerifier
|
||||
import org.fdroid.fdroid.DigestInputStream
|
||||
import java.io.InputStream
|
||||
import java.net.InetAddress
|
||||
import java.security.DigestInputStream
|
||||
import java.security.MessageDigest
|
||||
|
||||
internal actual fun getHttpClientEngineFactory(customDns: Dns?): HttpClientEngineFactory<*> {
|
||||
|
||||
@@ -5,51 +5,14 @@
|
||||
|
||||
package org.fdroid.fdroid
|
||||
|
||||
import java.io.FilterInputStream
|
||||
import java.io.InputStream
|
||||
import java.security.MessageDigest
|
||||
import java.security.DigestInputStream
|
||||
|
||||
/**
|
||||
* A [FilterInputStream] that updated the given [messageDigest] while reading from the stream.
|
||||
* Completes the hash computation by performing final operations such as padding
|
||||
* and returns the resulting hash as a hex string.
|
||||
* The digest is reset after this call is made,
|
||||
* so call this only once and hang on to the result.
|
||||
*/
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
public class DigestInputStream(
|
||||
inputStream: InputStream,
|
||||
private val messageDigest: MessageDigest,
|
||||
) : FilterInputStream(inputStream) {
|
||||
|
||||
override fun read(): Int {
|
||||
val b = `in`.read()
|
||||
if (b != -1) messageDigest.update(b.toByte())
|
||||
return b
|
||||
}
|
||||
|
||||
override fun read(b: ByteArray, off: Int, len: Int): Int {
|
||||
val numOfBytesRead = `in`.read(b, off, len)
|
||||
if (numOfBytesRead != -1) {
|
||||
messageDigest.update(b, off, numOfBytesRead)
|
||||
}
|
||||
return numOfBytesRead
|
||||
}
|
||||
|
||||
override fun markSupported(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun mark(readlimit: Int) {
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
|
||||
/**
|
||||
* Completes the hash computation by performing final operations such as padding
|
||||
* and returns the resulting hash as a hex string.
|
||||
* The digest is reset after this call is made,
|
||||
* so call this only once and hang on to the result.
|
||||
*/
|
||||
public fun getDigestHex(): String {
|
||||
return messageDigest.digest().toHex()
|
||||
}
|
||||
public fun DigestInputStream.getDigestHex(): String {
|
||||
return messageDigest.digest().toHex()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user