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:
parent
ac94b88d87
commit
fee7510496
10 changed files with 15 additions and 16 deletions
|
@ -9,7 +9,6 @@ import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
|
||||||
import java.util.Properties
|
import java.util.Properties
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.kotlin.dsl.configure
|
import org.gradle.kotlin.dsl.configure
|
||||||
import org.gradle.kotlin.dsl.provideDelegate
|
|
||||||
|
|
||||||
private const val KEYSTORE_CONFIG_PATH = "keystore.properties"
|
private const val KEYSTORE_CONFIG_PATH = "keystore.properties"
|
||||||
|
|
||||||
|
|
|
@ -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
|
* 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.
|
* patch versions along with one to prepare the next snapshot.
|
||||||
*/
|
*/
|
||||||
@Suppress("UnstableApiUsage", "NAME_SHADOWING", "Unused")
|
@Suppress("Unused")
|
||||||
class VersioningPlugin : Plugin<Project> {
|
class VersioningPlugin : Plugin<Project> {
|
||||||
|
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
package crowdin
|
package crowdin
|
||||||
|
|
||||||
/** Extension for configuring [CrowdinPlugin] */
|
/** Extension for configuring [CrowdinDownloadPlugin] */
|
||||||
interface CrowdinExtension {
|
interface CrowdinExtension {
|
||||||
|
|
||||||
/** Configure the project name on Crowdin */
|
/** Configure the project name on Crowdin */
|
||||||
|
|
|
@ -11,5 +11,4 @@ dependencies {
|
||||||
implementation(projects.coroutineUtils)
|
implementation(projects.coroutineUtils)
|
||||||
implementation(libs.testing.junit)
|
implementation(libs.testing.junit)
|
||||||
implementation(libs.kotlin.coroutines.test)
|
implementation(libs.kotlin.coroutines.test)
|
||||||
api(libs.testing.turbine)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,12 +33,12 @@ public class CoroutineTestRule(
|
||||||
override fun unconfined(): CoroutineDispatcher = testDispatcher
|
override fun unconfined(): CoroutineDispatcher = testDispatcher
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun starting(description: Description?) {
|
override fun starting(description: Description) {
|
||||||
super.starting(description)
|
super.starting(description)
|
||||||
Dispatchers.setMain(testDispatcher)
|
Dispatchers.setMain(testDispatcher)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun finished(description: Description?) {
|
override fun finished(description: Description) {
|
||||||
super.finished(description)
|
super.finished(description)
|
||||||
Dispatchers.resetMain()
|
Dispatchers.resetMain()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,11 @@ import kotlin.contracts.contract
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls the specified function [block] with [this] value as its receiver and returns its
|
* Calls the specified function [block] and returns its encapsulated result if invocation was
|
||||||
* encapsulated result if invocation was successful, catching any [Throwable] except
|
* successful, catching any [Throwable] except [CancellationException] that was thrown from the
|
||||||
* [CancellationException] that was thrown from the [block] function execution and encapsulating it
|
* [block] function execution and encapsulating it as a failure.
|
||||||
* as a failure.
|
|
||||||
*/
|
*/
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
public suspend inline fun <V> runSuspendCatching(block: () -> V): Result<V, Throwable> {
|
public suspend inline fun <V> runSuspendCatching(block: () -> V): Result<V, Throwable> {
|
||||||
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
|
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
|
* [CancellationException] that was thrown from the [block] function execution and encapsulating it
|
||||||
* as a failure.
|
* as a failure.
|
||||||
*/
|
*/
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
public suspend inline infix fun <T, V> T.runSuspendCatching(
|
public suspend inline infix fun <T, V> T.runSuspendCatching(
|
||||||
block: T.() -> V
|
block: T.() -> V
|
||||||
): Result<V, Throwable> {
|
): Result<V, Throwable> {
|
||||||
|
|
|
@ -16,7 +16,7 @@ public interface KeyManager<Key, KeyIdentifier> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a [key] into the store. If the key already exists, this method will return
|
* 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>
|
public suspend fun addKey(key: Key, replace: Boolean = false): Result<Key, Throwable>
|
||||||
|
|
||||||
|
|
|
@ -38,13 +38,12 @@ public sealed class GpgIdentifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
@OptIn(ExperimentalUnsignedTypes::class)
|
|
||||||
public fun fromString(identifier: String): GpgIdentifier? {
|
public fun fromString(identifier: String): GpgIdentifier? {
|
||||||
if (identifier.isEmpty()) return null
|
if (identifier.isEmpty()) return null
|
||||||
// Match long key IDs:
|
// Match long key IDs:
|
||||||
// FF22334455667788 or 0xFF22334455667788
|
// FF22334455667788 or 0xFF22334455667788
|
||||||
val maybeLongKeyId =
|
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) {
|
if (maybeLongKeyId != null) {
|
||||||
val keyId = maybeLongKeyId.toULong(16)
|
val keyId = maybeLongKeyId.toULong(16)
|
||||||
return KeyId(keyId.toLong())
|
return KeyId(keyId.toLong())
|
||||||
|
@ -53,7 +52,7 @@ public sealed class GpgIdentifier {
|
||||||
// Match fingerprints:
|
// Match fingerprints:
|
||||||
// FF223344556677889900112233445566778899 or 0xFF223344556677889900112233445566778899
|
// FF223344556677889900112233445566778899 or 0xFF223344556677889900112233445566778899
|
||||||
val maybeFingerprint =
|
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) {
|
if (maybeFingerprint != null) {
|
||||||
// Truncating to the long key ID is not a security issue since OpenKeychain only
|
// Truncating to the long key ID is not a security issue since OpenKeychain only
|
||||||
// accepts
|
// accepts
|
||||||
|
|
|
@ -161,17 +161,17 @@ class PGPKeyManagerTest {
|
||||||
@Test
|
@Test
|
||||||
fun getAllKeys() =
|
fun getAllKeys() =
|
||||||
scope.runTest {
|
scope.runTest {
|
||||||
// TODO: Should we check for more than 1 keys?
|
|
||||||
// Check if KeyManager returns no key
|
// Check if KeyManager returns no key
|
||||||
val noKeyList = keyManager.getAllKeys().unwrap()
|
val noKeyList = keyManager.getAllKeys().unwrap()
|
||||||
assertEquals(0, noKeyList.size)
|
assertEquals(0, noKeyList.size)
|
||||||
|
|
||||||
// Add key using KeyManager
|
// Add key using KeyManager
|
||||||
keyManager.addKey(key).unwrap()
|
keyManager.addKey(key).unwrap()
|
||||||
|
keyManager.addKey(PGPKey(getArmoredPrivateKeyWithMultipleIdentities())).unwrap()
|
||||||
|
|
||||||
// Check if KeyManager returns one key
|
// Check if KeyManager returns one key
|
||||||
val singleKeyList = keyManager.getAllKeys().unwrap()
|
val singleKeyList = keyManager.getAllKeys().unwrap()
|
||||||
assertEquals(1, singleKeyList.size)
|
assertEquals(2, singleKeyList.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -18,4 +18,5 @@ dependencies {
|
||||||
testImplementation(projects.coroutineUtilsTesting)
|
testImplementation(projects.coroutineUtilsTesting)
|
||||||
testImplementation(libs.bundles.testDependencies)
|
testImplementation(libs.bundles.testDependencies)
|
||||||
testImplementation(libs.kotlin.coroutines.test)
|
testImplementation(libs.kotlin.coroutines.test)
|
||||||
|
testImplementation(libs.testing.turbine)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue