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 ++++++++++ 6 files changed, 154 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 (limited to 'crypto/age') 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") + } +} -- cgit v1.2.3