From 62902ca80b2a0883d810518de8b1838f29a682eb Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 24 Apr 2022 21:25:34 +0530 Subject: Reorganize crypto-common code and fix a couple minor bugs (#1868) --- .../dev/msfjarvis/aps/crypto/CryptoException.kt | 29 --------------------- .../kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt | 2 +- .../msfjarvis/aps/crypto/errors/CryptoException.kt | 30 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 30 deletions(-) delete mode 100644 crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoException.kt create mode 100644 crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/errors/CryptoException.kt (limited to 'crypto-common') diff --git a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoException.kt b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoException.kt deleted file mode 100644 index 42429a14..00000000 --- a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/CryptoException.kt +++ /dev/null @@ -1,29 +0,0 @@ -package dev.msfjarvis.aps.crypto - -public sealed class CryptoException(message: String? = null) : Exception(message) - -/** Sealed exception types for [KeyManager]. */ -public sealed class KeyManagerException(message: String? = null) : CryptoException(message) { - - /** Store contains no keys. */ - public object NoKeysAvailableException : KeyManagerException("No keys were found") - - /** Key directory does not exist or cannot be accessed. */ - public object KeyDirectoryUnavailableException : - KeyManagerException("Key directory does not exist") - - /** Failed to delete given key. */ - public object KeyDeletionFailedException : KeyManagerException("Couldn't delete the key file") - - /** Failed to parse the key as a known type. */ - public object InvalidKeyException : - KeyManagerException("Given key cannot be parsed as a known key type") - - /** No key matching [keyId] could be found. */ - public class KeyNotFoundException(keyId: String) : - KeyManagerException("No key found with id: $keyId") - - /** Attempting to add another key for [keyId] without requesting a replace. */ - public class KeyAlreadyExistsException(keyId: String) : - KeyManagerException("Pre-existing key was found for $keyId") -} diff --git a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt index aa71abf6..71efb2fb 100644 --- a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt +++ b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/KeyManager.kt @@ -16,7 +16,7 @@ public interface KeyManager { /** * Inserts a [key] into the store. If the key already exists, this method will return - * [KeyManagerException.KeyAlreadyExistsException] unless [replace] is `true`. + * [KeyAlreadyExistsException] unless [replace] is `true`. */ public suspend fun addKey(key: Key, replace: Boolean = false): Result diff --git a/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/errors/CryptoException.kt b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/errors/CryptoException.kt new file mode 100644 index 00000000..5e911c35 --- /dev/null +++ b/crypto-common/src/main/kotlin/dev/msfjarvis/aps/crypto/errors/CryptoException.kt @@ -0,0 +1,30 @@ +package dev.msfjarvis.aps.crypto.errors + +import dev.msfjarvis.aps.crypto.KeyManager + +public sealed class CryptoException(message: String? = null) : Exception(message) + +/** Sealed exception types for [KeyManager]. */ +public sealed class KeyManagerException(message: String? = null) : CryptoException(message) + +/** Store contains no keys. */ +public object NoKeysAvailableException : KeyManagerException("No keys were found") + +/** Key directory does not exist or cannot be accessed. */ +public object KeyDirectoryUnavailableException : + KeyManagerException("Key directory does not exist") + +/** Failed to delete given key. */ +public object KeyDeletionFailedException : KeyManagerException("Couldn't delete the key file") + +/** Failed to parse the key as a known type. */ +public object InvalidKeyException : + KeyManagerException("Given key cannot be parsed as a known key type") + +/** No key matching [keyId] could be found. */ +public class KeyNotFoundException(keyId: String) : + KeyManagerException("No key found with id: $keyId") + +/** Attempting to add another key for [keyId] without requesting a replace. */ +public class KeyAlreadyExistsException(keyId: String) : + KeyManagerException("Pre-existing key was found for $keyId") -- cgit v1.2.3