From 688d4f63dbcfcf766681f2cb23597de3dbf8cc60 Mon Sep 17 00:00:00 2001 From: Ron Lauren Hombre <118486316+ronhombre@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:37:09 +0800 Subject: [PATCH] Pre-1.x.x Deprecation * These methods will be fully deprecated in the 1.0.0 release --- .../kotlin/asia/hombre/kyber/KyberCipherText.kt | 8 ++++++++ .../kotlin/asia/hombre/kyber/KyberDecapsulationKey.kt | 8 ++++++++ .../kotlin/asia/hombre/kyber/KyberDecryptionKey.kt | 8 ++++++++ .../kotlin/asia/hombre/kyber/KyberEncapsulationKey.kt | 7 +++++++ .../kotlin/asia/hombre/kyber/KyberEncryptionKey.kt | 8 ++++++++ .../hombre/kyber/exceptions/InvalidKyberKeyException.kt | 2 +- .../kyber/exceptions/UnsupportedKyberVariantException.kt | 2 +- .../kotlin/asia/hombre/kyber/interfaces/Convertible.kt | 2 ++ 8 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/commonMain/kotlin/asia/hombre/kyber/KyberCipherText.kt b/src/commonMain/kotlin/asia/hombre/kyber/KyberCipherText.kt index 18fd252..733c6d7 100644 --- a/src/commonMain/kotlin/asia/hombre/kyber/KyberCipherText.kt +++ b/src/commonMain/kotlin/asia/hombre/kyber/KyberCipherText.kt @@ -96,6 +96,7 @@ class KyberCipherText internal constructor( //TODO: Copy parameter variables */ @JvmStatic @Throws(UnsupportedKyberVariantException::class, IllegalArgumentException::class) + @Deprecated("Conversion from hex values are up to the user.", level = DeprecationLevel.WARNING) fun fromHex(hexString: String): KyberCipherText { return fromBytes(KyberMath.decodeHex(hexString)) } @@ -111,6 +112,13 @@ class KyberCipherText internal constructor( //TODO: Copy parameter variables @JvmStatic @Throws(UnsupportedKyberVariantException::class, IllegalArgumentException::class) @OptIn(ExperimentalEncodingApi::class) + @Deprecated("Conversion from base64 values are up to the user.", level = DeprecationLevel.WARNING, + replaceWith = ReplaceWith( + "fromBytes(Base64.decode(base64String))", + "asia.hombre.kyber.KyberCipherText.Companion.fromBytes", + "kotlin.io.encoding.Base64" + ) + ) fun fromBase64(base64String: String): KyberCipherText { return fromBytes(Base64.decode(base64String)) } diff --git a/src/commonMain/kotlin/asia/hombre/kyber/KyberDecapsulationKey.kt b/src/commonMain/kotlin/asia/hombre/kyber/KyberDecapsulationKey.kt index 63008f9..603af50 100644 --- a/src/commonMain/kotlin/asia/hombre/kyber/KyberDecapsulationKey.kt +++ b/src/commonMain/kotlin/asia/hombre/kyber/KyberDecapsulationKey.kt @@ -107,6 +107,7 @@ class KyberDecapsulationKey internal constructor( */ @JvmStatic @Throws(UnsupportedKyberVariantException::class, IllegalArgumentException::class) + @Deprecated("Conversion from hex values are up to the user.", level = DeprecationLevel.WARNING) fun fromHex(hexString: String): KyberDecapsulationKey { return fromBytes(KyberMath.decodeHex(hexString)) } @@ -122,6 +123,13 @@ class KyberDecapsulationKey internal constructor( @JvmStatic @Throws(UnsupportedKyberVariantException::class) @OptIn(ExperimentalEncodingApi::class) + @Deprecated("Conversion from base64 values are up to the user.", level = DeprecationLevel.WARNING, + replaceWith = ReplaceWith( + "fromBytes(Base64.decode(base64String))", + "asia.hombre.kyber.KyberDecapsulationKey.Companion.fromBytes", + "kotlin.io.encoding.Base64" + ) + ) fun fromBase64(base64String: String): KyberDecapsulationKey { return fromBytes(Base64.decode(base64String)) } diff --git a/src/commonMain/kotlin/asia/hombre/kyber/KyberDecryptionKey.kt b/src/commonMain/kotlin/asia/hombre/kyber/KyberDecryptionKey.kt index d1a7c06..0850f9d 100644 --- a/src/commonMain/kotlin/asia/hombre/kyber/KyberDecryptionKey.kt +++ b/src/commonMain/kotlin/asia/hombre/kyber/KyberDecryptionKey.kt @@ -88,6 +88,7 @@ class KyberDecryptionKey internal constructor( */ @JvmStatic @Throws(UnsupportedKyberVariantException::class, IllegalArgumentException::class) + @Deprecated("Conversion from hex values are up to the user.", level = DeprecationLevel.WARNING) fun fromHex(hexString: String): KyberDecryptionKey { return fromBytes(KyberMath.decodeHex(hexString)) } @@ -103,6 +104,13 @@ class KyberDecryptionKey internal constructor( @JvmStatic @Throws(UnsupportedKyberVariantException::class, IllegalArgumentException::class) @OptIn(ExperimentalEncodingApi::class) + @Deprecated("Conversion from base64 values are up to the user.", level = DeprecationLevel.WARNING, + replaceWith = ReplaceWith( + "fromBytes(Base64.decode(base64String))", + "asia.hombre.kyber.KyberDecryptionKey.Companion.fromBytes", + "kotlin.io.encoding.Base64" + ) + ) fun fromBase64(base64String: String): KyberDecryptionKey { return fromBytes(Base64.decode(base64String)) } diff --git a/src/commonMain/kotlin/asia/hombre/kyber/KyberEncapsulationKey.kt b/src/commonMain/kotlin/asia/hombre/kyber/KyberEncapsulationKey.kt index c877c08..c09f4e1 100644 --- a/src/commonMain/kotlin/asia/hombre/kyber/KyberEncapsulationKey.kt +++ b/src/commonMain/kotlin/asia/hombre/kyber/KyberEncapsulationKey.kt @@ -75,6 +75,7 @@ class KyberEncapsulationKey internal constructor( */ @JvmStatic @Throws(UnsupportedKyberVariantException::class, IllegalArgumentException::class) + @Deprecated("Conversion from hex values are up to the user.", level = DeprecationLevel.WARNING) fun fromHex(hexString: String): KyberEncapsulationKey { return KyberEncapsulationKey(KyberEncryptionKey.fromHex(hexString)) } @@ -89,6 +90,12 @@ class KyberEncapsulationKey internal constructor( */ @JvmStatic @Throws(UnsupportedKyberVariantException::class, IllegalArgumentException::class) + @Deprecated("Conversion from base64 values are up to the user.", level = DeprecationLevel.WARNING, + replaceWith = ReplaceWith( + "KyberEncapsulationKey(KyberEncryptionKey.fromBase64(base64String))", + "asia.hombre.kyber.KyberEncapsulationKey" + ) + ) fun fromBase64(base64String: String): KyberEncapsulationKey { return KyberEncapsulationKey(KyberEncryptionKey.fromBase64(base64String)) } diff --git a/src/commonMain/kotlin/asia/hombre/kyber/KyberEncryptionKey.kt b/src/commonMain/kotlin/asia/hombre/kyber/KyberEncryptionKey.kt index ae25739..e75c4f8 100644 --- a/src/commonMain/kotlin/asia/hombre/kyber/KyberEncryptionKey.kt +++ b/src/commonMain/kotlin/asia/hombre/kyber/KyberEncryptionKey.kt @@ -102,6 +102,7 @@ class KyberEncryptionKey internal constructor( */ @JvmStatic @Throws(UnsupportedKyberVariantException::class, IllegalArgumentException::class) + @Deprecated("Conversion from hex values are up to the user.", level = DeprecationLevel.WARNING) fun fromHex(hexString: String): KyberEncryptionKey { return fromBytes(KyberMath.decodeHex(hexString)) } @@ -117,6 +118,13 @@ class KyberEncryptionKey internal constructor( @JvmStatic @Throws(UnsupportedKyberVariantException::class, IllegalArgumentException::class) @OptIn(ExperimentalEncodingApi::class) + @Deprecated("Conversion from base64 values are up to the user.", level = DeprecationLevel.WARNING, + replaceWith = ReplaceWith( + "fromBytes(Base64.decode(base64String))", + "asia.hombre.kyber.KyberEncryptionKey.Companion.fromBytes", + "kotlin.io.encoding.Base64" + ) + ) fun fromBase64(base64String: String): KyberEncryptionKey { return fromBytes(Base64.decode(base64String)) } diff --git a/src/commonMain/kotlin/asia/hombre/kyber/exceptions/InvalidKyberKeyException.kt b/src/commonMain/kotlin/asia/hombre/kyber/exceptions/InvalidKyberKeyException.kt index 0659a1c..f1e5ab6 100644 --- a/src/commonMain/kotlin/asia/hombre/kyber/exceptions/InvalidKyberKeyException.kt +++ b/src/commonMain/kotlin/asia/hombre/kyber/exceptions/InvalidKyberKeyException.kt @@ -21,4 +21,4 @@ package asia.hombre.kyber.exceptions /** * When a key fails a validity check. */ -class InvalidKyberKeyException(override val message: String): Exception("This may not be a Kyber Key! Reason: $message") \ No newline at end of file +class InvalidKyberKeyException(override val message: String): Exception("This may not be an ML-KEM Key! Reason: $message") \ No newline at end of file diff --git a/src/commonMain/kotlin/asia/hombre/kyber/exceptions/UnsupportedKyberVariantException.kt b/src/commonMain/kotlin/asia/hombre/kyber/exceptions/UnsupportedKyberVariantException.kt index ed49528..7c14fca 100644 --- a/src/commonMain/kotlin/asia/hombre/kyber/exceptions/UnsupportedKyberVariantException.kt +++ b/src/commonMain/kotlin/asia/hombre/kyber/exceptions/UnsupportedKyberVariantException.kt @@ -21,4 +21,4 @@ package asia.hombre.kyber.exceptions /** * When an unsupported ML-KEM variant was attempted to be used. */ -class UnsupportedKyberVariantException(override val message: String): Exception("This Kyber variant is not yet supported! Reason: $message") \ No newline at end of file +class UnsupportedKyberVariantException(override val message: String): Exception("This ML-KEM variant is not yet supported! Reason: $message") \ No newline at end of file diff --git a/src/commonMain/kotlin/asia/hombre/kyber/interfaces/Convertible.kt b/src/commonMain/kotlin/asia/hombre/kyber/interfaces/Convertible.kt index 13a4803..5333e99 100644 --- a/src/commonMain/kotlin/asia/hombre/kyber/interfaces/Convertible.kt +++ b/src/commonMain/kotlin/asia/hombre/kyber/interfaces/Convertible.kt @@ -27,6 +27,8 @@ import kotlin.js.JsExport @OptIn(ExperimentalJsExport::class) @JsExport internal interface Convertible { + @Deprecated("Conversion to hex values are up to the user.", level = DeprecationLevel.WARNING) fun toHex(isUppercase: Boolean = true): String + @Deprecated("Conversion to base64 values are up to the user.", level = DeprecationLevel.WARNING) fun toBase64(): String } \ No newline at end of file