Skip to content

Commit 01e0ea6

Browse files
committed
Throw ISE instead of custom exception for now
1 parent e102d2b commit 01e0ea6

File tree

12 files changed

+29
-23
lines changed

12 files changed

+29
-23
lines changed
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
/*
2-
* Copyright (c) 2023 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright (c) 2023-2024 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package dev.whyoleg.cryptography
66

7+
@Suppress("DEPRECATION_ERROR")
8+
@Deprecated(
9+
"IllegalStateException is throw instead",
10+
level = DeprecationLevel.ERROR
11+
)
712
public class CryptographyAlgorithmNotFoundException(
813
algorithm: CryptographyAlgorithmId<*>,
914
) : CryptographyException("Algorithm not found: $algorithm")

cryptography-core/src/commonMain/kotlin/CryptographyException.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
/*
2-
* Copyright (c) 2023 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright (c) 2023-2024 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package dev.whyoleg.cryptography
66

7+
@Deprecated(
8+
"IllegalStateException is throw instead",
9+
level = DeprecationLevel.ERROR
10+
)
711
public open class CryptographyException : RuntimeException {
812
public constructor(message: String?) : super(message)
913
public constructor(message: String?, cause: Throwable?) : super(message, cause)

cryptography-core/src/commonMain/kotlin/CryptographyProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public abstract class CryptographyProvider {
1010

1111
public abstract fun <A : CryptographyAlgorithm> getOrNull(identifier: CryptographyAlgorithmId<A>): A?
1212
public open fun <A : CryptographyAlgorithm> get(identifier: CryptographyAlgorithmId<A>): A =
13-
getOrNull(identifier) ?: throw CryptographyAlgorithmNotFoundException(identifier)
13+
getOrNull(identifier) ?: throw IllegalStateException("Algorithm not found: $identifier")
1414

1515
@CryptographyProviderApi
1616
public object Registry {

cryptography-providers/apple/src/commonMain/kotlin/algorithms/CCHmac.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal object CCHmac : HMAC {
2222
SHA256 -> HmacKeyDecoder(kCCHmacAlgSHA256, CC_SHA256_BLOCK_BYTES, CC_SHA256_DIGEST_LENGTH)
2323
SHA384 -> HmacKeyDecoder(kCCHmacAlgSHA384, CC_SHA384_BLOCK_BYTES, CC_SHA384_DIGEST_LENGTH)
2424
SHA512 -> HmacKeyDecoder(kCCHmacAlgSHA512, CC_SHA512_BLOCK_BYTES, CC_SHA512_DIGEST_LENGTH)
25-
else -> throw CryptographyException("Unsupported hash algorithm: $digest")
25+
else -> throw IllegalStateException("Unsupported hash algorithm: $digest")
2626
}
2727
}
2828

@@ -33,7 +33,7 @@ internal object CCHmac : HMAC {
3333
SHA256 -> HmacKeyGenerator(kCCHmacAlgSHA256, CC_SHA256_BLOCK_BYTES, CC_SHA256_DIGEST_LENGTH)
3434
SHA384 -> HmacKeyGenerator(kCCHmacAlgSHA384, CC_SHA384_BLOCK_BYTES, CC_SHA384_DIGEST_LENGTH)
3535
SHA512 -> HmacKeyGenerator(kCCHmacAlgSHA512, CC_SHA512_BLOCK_BYTES, CC_SHA512_DIGEST_LENGTH)
36-
else -> throw CryptographyException("Unsupported hash algorithm: $digest")
36+
else -> throw IllegalStateException("Unsupported hash algorithm: $digest")
3737
}
3838
}
3939
}

cryptography-providers/apple/src/commonMain/kotlin/internal/digest.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal fun CryptographyAlgorithmId<Digest>.rsaPssSecKeyAlgorithm(): SecKeyAlgo
1515
SHA256 -> kSecKeyAlgorithmRSASignatureMessagePSSSHA256
1616
SHA384 -> kSecKeyAlgorithmRSASignatureMessagePSSSHA384
1717
SHA512 -> kSecKeyAlgorithmRSASignatureMessagePSSSHA512
18-
else -> throw CryptographyException("Unsupported hash algorithm: $this")
18+
else -> throw IllegalStateException("Unsupported hash algorithm: $this")
1919
}
2020

2121
internal fun CryptographyAlgorithmId<Digest>.rsaPkcs1SecKeyAlgorithm(): SecKeyAlgorithm? = when (this) {
@@ -24,7 +24,7 @@ internal fun CryptographyAlgorithmId<Digest>.rsaPkcs1SecKeyAlgorithm(): SecKeyAl
2424
SHA256 -> kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA256
2525
SHA384 -> kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA384
2626
SHA512 -> kSecKeyAlgorithmRSASignatureMessagePKCS1v15SHA512
27-
else -> throw CryptographyException("Unsupported hash algorithm: $this")
27+
else -> throw IllegalStateException("Unsupported hash algorithm: $this")
2828
}
2929

3030
internal fun CryptographyAlgorithmId<Digest>.rsaOaepSecKeyAlgorithm(): SecKeyAlgorithm? = when (this) {
@@ -33,7 +33,7 @@ internal fun CryptographyAlgorithmId<Digest>.rsaOaepSecKeyAlgorithm(): SecKeyAlg
3333
SHA256 -> kSecKeyAlgorithmRSAEncryptionOAEPSHA256
3434
SHA384 -> kSecKeyAlgorithmRSAEncryptionOAEPSHA384
3535
SHA512 -> kSecKeyAlgorithmRSAEncryptionOAEPSHA512
36-
else -> throw CryptographyException("Unsupported hash algorithm: $this")
36+
else -> throw IllegalStateException("Unsupported hash algorithm: $this")
3737
}
3838

3939
internal fun CryptographyAlgorithmId<Digest>.ecdsaSecKeyAlgorithm(): SecKeyAlgorithm? = when (this) {
@@ -42,7 +42,7 @@ internal fun CryptographyAlgorithmId<Digest>.ecdsaSecKeyAlgorithm(): SecKeyAlgor
4242
SHA256 -> kSecKeyAlgorithmECDSASignatureMessageX962SHA256
4343
SHA384 -> kSecKeyAlgorithmECDSASignatureMessageX962SHA384
4444
SHA512 -> kSecKeyAlgorithmECDSASignatureMessageX962SHA512
45-
else -> throw CryptographyException("Unsupported hash algorithm: $this")
45+
else -> throw IllegalStateException("Unsupported hash algorithm: $this")
4646
}
4747

4848
internal fun CryptographyAlgorithmId<Digest>.pbkdh2Algorithm(): CCPseudoRandomAlgorithm = when (this) {
@@ -51,5 +51,5 @@ internal fun CryptographyAlgorithmId<Digest>.pbkdh2Algorithm(): CCPseudoRandomAl
5151
SHA256 -> kCCPRFHmacAlgSHA256
5252
SHA384 -> kCCPRFHmacAlgSHA384
5353
SHA512 -> kCCPRFHmacAlgSHA512
54-
else -> throw CryptographyException("Unsupported hash algorithm: $this")
54+
else -> throw IllegalStateException("Unsupported hash algorithm: $this")
5555
}

cryptography-providers/jdk/src/jvmMain/kotlin/JdkCryptographyState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,5 @@ internal fun CryptographyAlgorithmId<Digest>.hashAlgorithmName(): String = when
9191
SHA3_256 -> "SHA3-256"
9292
SHA3_384 -> "SHA3-384"
9393
SHA3_512 -> "SHA3-512"
94-
else -> throw CryptographyException("Unsupported hash algorithm: $this")
94+
else -> throw IllegalStateException("Unsupported hash algorithm: $this")
9595
}

cryptography-providers/jdk/src/jvmMain/kotlin/algorithms/JdkHmac.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ private fun CryptographyAlgorithmId<Digest>.blockSize(): Int = when (this) {
5050
SHA3_256 -> 136
5151
SHA3_384 -> 104
5252
SHA3_512 -> 72
53-
else -> throw CryptographyException("Unsupported hash algorithm: $this")
53+
else -> throw IllegalStateException("Unsupported hash algorithm: $this")
5454
} * 8

cryptography-providers/jdk/src/jvmMain/kotlin/algorithms/JdkRsa.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal fun CryptographyAlgorithmId<Digest>.rsaHashAlgorithmName(): String = wh
2323
SHA3_256 -> "SHA3-256"
2424
SHA3_384 -> "SHA3-384"
2525
SHA3_512 -> "SHA3-512"
26-
else -> throw CryptographyException("Unsupported hash algorithm: $this")
26+
else -> throw IllegalStateException("Unsupported hash algorithm: $this")
2727
}
2828

2929
internal abstract class RsaPublicKeyDecoder<K : RSA.PublicKey>(

cryptography-providers/openssl3/api/src/commonMain/kotlin/internal/errors.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/*
2-
* Copyright (c) 2023 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright (c) 2023-2024 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package dev.whyoleg.cryptography.providers.openssl3.internal
66

7-
import dev.whyoleg.cryptography.*
87
import dev.whyoleg.cryptography.providers.openssl3.internal.cinterop.*
98
import kotlinx.cinterop.*
109
import platform.posix.*
@@ -39,5 +38,5 @@ private fun fail(result: Int): Nothing {
3938
if (code.toInt() != 0) append(", ")
4039
} while (code.toInt() != 0)
4140
}
42-
throw CryptographyException("OPENSSL failure: $message (result: $result)")
41+
throw IllegalStateException("OPENSSL failure: $message (result: $result)")
4342
}

cryptography-providers/openssl3/api/src/commonMain/kotlin/internal/hash.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ internal fun hashAlgorithm(digest: CryptographyAlgorithmId<Digest>): String = wh
1717
SHA3_256 -> "SHA3-256"
1818
SHA3_384 -> "SHA3-384"
1919
SHA3_512 -> "SHA3-512"
20-
else -> throw CryptographyException("Unsupported hash algorithm: $digest")
20+
else -> throw IllegalStateException("Unsupported hash algorithm: $digest")
2121
}

0 commit comments

Comments
 (0)