Miscellaneous cleanups (#1934)

* build-logic: cleanups

* coroutine-utils-testing: cleanups

* coroutine-utils: cleanups

* crypto-common: cleanups

* crypto-pgpainless: cleanups

* format-common: cleanups
This commit is contained in:
Harsh Shandilya 2022-06-04 14:41:52 +05:30 committed by GitHub
parent ac94b88d87
commit fee7510496
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 15 additions and 16 deletions

View file

@ -9,7 +9,6 @@ import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import java.util.Properties
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.provideDelegate
private const val KEYSTORE_CONFIG_PATH = "keystore.properties"

View file

@ -18,7 +18,7 @@ import org.gradle.kotlin.dsl.register
* the [Project.getBuildDir] directory. It also adds Gradle tasks to bump the major, minor, and
* patch versions along with one to prepare the next snapshot.
*/
@Suppress("UnstableApiUsage", "NAME_SHADOWING", "Unused")
@Suppress("Unused")
class VersioningPlugin : Plugin<Project> {
override fun apply(project: Project) {

View file

@ -5,7 +5,7 @@
package crowdin
/** Extension for configuring [CrowdinPlugin] */
/** Extension for configuring [CrowdinDownloadPlugin] */
interface CrowdinExtension {
/** Configure the project name on Crowdin */

View file

@ -11,5 +11,4 @@ dependencies {
implementation(projects.coroutineUtils)
implementation(libs.testing.junit)
implementation(libs.kotlin.coroutines.test)
api(libs.testing.turbine)
}

View file

@ -33,12 +33,12 @@ public class CoroutineTestRule(
override fun unconfined(): CoroutineDispatcher = testDispatcher
}
override fun starting(description: Description?) {
override fun starting(description: Description) {
super.starting(description)
Dispatchers.setMain(testDispatcher)
}
override fun finished(description: Description?) {
override fun finished(description: Description) {
super.finished(description)
Dispatchers.resetMain()
}

View file

@ -12,11 +12,11 @@ import kotlin.contracts.contract
import kotlinx.coroutines.CancellationException
/**
* Calls the specified function [block] with [this] value as its receiver and returns its
* encapsulated result if invocation was successful, catching any [Throwable] except
* [CancellationException] that was thrown from the [block] function execution and encapsulating it
* as a failure.
* Calls the specified function [block] and returns its encapsulated result if invocation was
* successful, catching any [Throwable] except [CancellationException] that was thrown from the
* [block] function execution and encapsulating it as a failure.
*/
@OptIn(ExperimentalContracts::class)
public suspend inline fun <V> runSuspendCatching(block: () -> V): Result<V, Throwable> {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
@ -34,6 +34,7 @@ public suspend inline fun <V> runSuspendCatching(block: () -> V): Result<V, Thro
* [CancellationException] that was thrown from the [block] function execution and encapsulating it
* as a failure.
*/
@OptIn(ExperimentalContracts::class)
public suspend inline infix fun <T, V> T.runSuspendCatching(
block: T.() -> V
): Result<V, Throwable> {

View file

@ -16,7 +16,7 @@ public interface KeyManager<Key, KeyIdentifier> {
/**
* Inserts a [key] into the store. If the key already exists, this method will return
* [KeyAlreadyExistsException] unless [replace] is `true`.
* [dev.msfjarvis.aps.crypto.errors.KeyAlreadyExistsException] unless [replace] is `true`.
*/
public suspend fun addKey(key: Key, replace: Boolean = false): Result<Key, Throwable>

View file

@ -38,13 +38,12 @@ public sealed class GpgIdentifier {
}
public companion object {
@OptIn(ExperimentalUnsignedTypes::class)
public fun fromString(identifier: String): GpgIdentifier? {
if (identifier.isEmpty()) return null
// Match long key IDs:
// FF22334455667788 or 0xFF22334455667788
val maybeLongKeyId =
identifier.removePrefix("0x").takeIf { it.matches("[a-fA-F0-9]{16}".toRegex()) }
identifier.removePrefix("0x").takeIf { it.matches("[a-fA-F\\d]{16}".toRegex()) }
if (maybeLongKeyId != null) {
val keyId = maybeLongKeyId.toULong(16)
return KeyId(keyId.toLong())
@ -53,7 +52,7 @@ public sealed class GpgIdentifier {
// Match fingerprints:
// FF223344556677889900112233445566778899 or 0xFF223344556677889900112233445566778899
val maybeFingerprint =
identifier.removePrefix("0x").takeIf { it.matches("[a-fA-F0-9]{40}".toRegex()) }
identifier.removePrefix("0x").takeIf { it.matches("[a-fA-F\\d]{40}".toRegex()) }
if (maybeFingerprint != null) {
// Truncating to the long key ID is not a security issue since OpenKeychain only
// accepts

View file

@ -161,17 +161,17 @@ class PGPKeyManagerTest {
@Test
fun getAllKeys() =
scope.runTest {
// TODO: Should we check for more than 1 keys?
// Check if KeyManager returns no key
val noKeyList = keyManager.getAllKeys().unwrap()
assertEquals(0, noKeyList.size)
// Add key using KeyManager
keyManager.addKey(key).unwrap()
keyManager.addKey(PGPKey(getArmoredPrivateKeyWithMultipleIdentities())).unwrap()
// Check if KeyManager returns one key
val singleKeyList = keyManager.getAllKeys().unwrap()
assertEquals(1, singleKeyList.size)
assertEquals(2, singleKeyList.size)
}
@Test

View file

@ -18,4 +18,5 @@ dependencies {
testImplementation(projects.coroutineUtilsTesting)
testImplementation(libs.bundles.testDependencies)
testImplementation(libs.kotlin.coroutines.test)
testImplementation(libs.testing.turbine)
}