From ae7487e76f8da04b7da7268980830f3580389926 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Wed, 14 Aug 2024 00:10:22 +0530 Subject: fix(crypto/age): init --- crypto/age/build.gradle.kts | 18 +++++++ crypto/age/lint-baseline.xml | 59 ++++++++++++++++++++++ .../app/passwordstore/crypto/AgeDecryptOptions.kt | 18 +++++++ .../app/passwordstore/crypto/AgeEncryptOptions.kt | 18 +++++++ .../main/kotlin/app/passwordstore/crypto/AgeKey.kt | 14 +++++ .../app/passwordstore/crypto/AgeKeyManager.kt | 27 ++++++++++ gradle/libs.versions.toml | 1 + settings.gradle.kts | 2 + 8 files changed, 157 insertions(+) create mode 100644 crypto/age/build.gradle.kts create mode 100644 crypto/age/lint-baseline.xml create mode 100644 crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeDecryptOptions.kt create mode 100644 crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeEncryptOptions.kt create mode 100644 crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeKey.kt create mode 100644 crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeKeyManager.kt diff --git a/crypto/age/build.gradle.kts b/crypto/age/build.gradle.kts new file mode 100644 index 00000000..dd44966b --- /dev/null +++ b/crypto/age/build.gradle.kts @@ -0,0 +1,18 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ +plugins { id("com.github.android-password-store.kotlin-jvm-library") } + +dependencies { + api(projects.crypto.common) + implementation(libs.androidx.annotation) + implementation(libs.aps.kage) + implementation(libs.dagger.hilt.core) + implementation(libs.kotlinx.coroutines.core) + implementation(libs.thirdparty.kotlinResult) + implementation(libs.thirdparty.kotlinResult.coroutines) + testImplementation(libs.bundles.testDependencies) + testImplementation(libs.kotlinx.coroutines.test) + testImplementation(libs.testing.testparameterinjector) +} diff --git a/crypto/age/lint-baseline.xml b/crypto/age/lint-baseline.xml new file mode 100644 index 00000000..73349b64 --- /dev/null +++ b/crypto/age/lint-baseline.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeDecryptOptions.kt b/crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeDecryptOptions.kt new file mode 100644 index 00000000..49a5dbfe --- /dev/null +++ b/crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeDecryptOptions.kt @@ -0,0 +1,18 @@ +package app.passwordstore.crypto + +/** [CryptoOptions] implementation for [kage.Age] decryption operations. */ +public class AgeDecryptOptions private constructor(private val values: Map) : + CryptoOptions { + + override fun isOptionEnabled(option: String): Boolean { + return values.getOrDefault(option, false) + } + + /** Builder for [AgeDecryptOptions]. */ + public class Builder { + /** Build the final [AgeDecryptOptions] object. */ + public fun build(): AgeDecryptOptions { + return AgeDecryptOptions(emptyMap()) + } + } +} diff --git a/crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeEncryptOptions.kt b/crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeEncryptOptions.kt new file mode 100644 index 00000000..fdac1a72 --- /dev/null +++ b/crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeEncryptOptions.kt @@ -0,0 +1,18 @@ +package app.passwordstore.crypto + +/** [CryptoOptions] implementation for [kage.Age] encryption operations. */ +public class AgeEncryptOptions private constructor(private val values: Map) : + CryptoOptions { + + override fun isOptionEnabled(option: String): Boolean { + return values.getOrDefault(option, false) + } + + /** Builder for [AgeEncryptOptions]. */ + public class Builder { + /** Build the final [AgeEncryptOptions] object. */ + public fun build(): AgeEncryptOptions { + return AgeEncryptOptions(emptyMap()) + } + } +} diff --git a/crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeKey.kt b/crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeKey.kt new file mode 100644 index 00000000..3c3ff9fd --- /dev/null +++ b/crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeKey.kt @@ -0,0 +1,14 @@ +package app.passwordstore.crypto + +import kage.Identity +import kage.Recipient + +/** Sealed hierarchy for the types of keys that [kage.Age] expects. */ +public sealed interface AgeKey { + + /** The public key in [kage.Age], wrapping a [kage.Recipient]. */ + @JvmInline public value class Public(public val recipient: Recipient) : AgeKey + + /** The private key in [kage.Age], wrapping a [kage.Identity]. */ + @JvmInline public value class Private(public val identity: Identity) : AgeKey +} diff --git a/crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeKeyManager.kt b/crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeKeyManager.kt new file mode 100644 index 00000000..ddf5a469 --- /dev/null +++ b/crypto/age/src/main/kotlin/app/passwordstore/crypto/AgeKeyManager.kt @@ -0,0 +1,27 @@ +package app.passwordstore.crypto + +import com.github.michaelbull.result.Result + +/** [KeyManager] implementation for [kage.Age]-based keys. */ +public class AgeKeyManager : KeyManager { + + override suspend fun addKey(key: AgeKey, replace: Boolean): Result { + TODO("Not yet implemented") + } + + override suspend fun removeKey(identifier: String): Result { + TODO("Not yet implemented") + } + + override suspend fun getKeyById(id: String): Result { + TODO("Not yet implemented") + } + + override suspend fun getAllKeys(): Result, Throwable> { + TODO("Not yet implemented") + } + + override suspend fun getKeyId(key: AgeKey): String? { + TODO("Not yet implemented") + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 898526c1..3353cb4c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -32,6 +32,7 @@ androidx-recyclerview = "androidx.recyclerview:recyclerview:1.4.0-alpha02" androidx-recyclerviewSelection = "androidx.recyclerview:recyclerview-selection:1.2.0-alpha01" androidx-security = "androidx.security:security-crypto-ktx:1.1.0-alpha06" androidx-swiperefreshlayout = "androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01" +aps-kage = "com.github.android-password-store:kage:0.2.0" aps-sublimeFuzzy = "com.github.android-password-store:sublime-fuzzy:2.3.4" aps-zxingAndroidEmbedded = "com.github.android-password-store:zxing-android-embedded:4.2.1" build-agp = { module = "com.android.tools.build:gradle", version.ref = "agp" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 002fac0c..e6f6c9ca 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -88,6 +88,8 @@ include("coroutine-utils") include("crypto:common") +include("crypto:age") + include("crypto:pgpainless") include("format:common") -- cgit v1.2.3