From 25cc83b9e2d6c82aee54d6e498e0c656f56eee47 Mon Sep 17 00:00:00 2001 From: Oleg Yukhnevich Date: Fri, 4 Oct 2024 08:45:13 +0300 Subject: [PATCH] Add API for streaming encryption/decryption --- cryptography-core/api/cryptography-core.api | 36 ++++++ .../api/cryptography-core.klib.api | 36 ++++++ .../src/commonMain/kotlin/algorithms/AES.kt | 93 ++++++++++++++ .../kotlin/operations/AuthenticatedCipher.kt | 115 +++++++++++++++--- .../commonMain/kotlin/operations/Cipher.kt | 37 +++++- 5 files changed, 292 insertions(+), 25 deletions(-) diff --git a/cryptography-core/api/cryptography-core.api b/cryptography-core/api/cryptography-core.api index ea82dfd6..a0d57471 100644 --- a/cryptography-core/api/cryptography-core.api +++ b/cryptography-core/api/cryptography-core.api @@ -149,6 +149,12 @@ public abstract interface class dev/whyoleg/cryptography/algorithms/AES$IvAuthen public fun decryptWithIvBlocking (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/bytestring/ByteString; public fun decryptWithIvBlocking ([B[B)[B public abstract fun decryptWithIvBlocking ([B[B[B)[B + public fun decryptingSinkWithIv (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/RawSink;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/RawSink; + public fun decryptingSinkWithIv ([BLkotlinx/io/RawSink;)Lkotlinx/io/RawSink; + public abstract fun decryptingSinkWithIv ([BLkotlinx/io/RawSink;[B)Lkotlinx/io/RawSink; + public fun decryptingSourceWithIv (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/RawSource;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/RawSource; + public fun decryptingSourceWithIv ([BLkotlinx/io/RawSource;)Lkotlinx/io/RawSource; + public abstract fun decryptingSourceWithIv ([BLkotlinx/io/RawSource;[B)Lkotlinx/io/RawSource; } public abstract interface class dev/whyoleg/cryptography/algorithms/AES$IvAuthenticatedEncryptor : dev/whyoleg/cryptography/algorithms/AES$IvEncryptor, dev/whyoleg/cryptography/operations/AuthenticatedEncryptor { @@ -164,6 +170,12 @@ public abstract interface class dev/whyoleg/cryptography/algorithms/AES$IvAuthen public fun encryptWithIvBlocking (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/bytestring/ByteString; public fun encryptWithIvBlocking ([B[B)[B public abstract fun encryptWithIvBlocking ([B[B[B)[B + public fun encryptingSinkWithIv (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/RawSink;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/RawSink; + public fun encryptingSinkWithIv ([BLkotlinx/io/RawSink;)Lkotlinx/io/RawSink; + public abstract fun encryptingSinkWithIv ([BLkotlinx/io/RawSink;[B)Lkotlinx/io/RawSink; + public fun encryptingSourceWithIv (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/RawSource;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/RawSource; + public fun encryptingSourceWithIv ([BLkotlinx/io/RawSource;)Lkotlinx/io/RawSource; + public abstract fun encryptingSourceWithIv ([BLkotlinx/io/RawSource;[B)Lkotlinx/io/RawSource; } public abstract interface class dev/whyoleg/cryptography/algorithms/AES$IvCipher : dev/whyoleg/cryptography/algorithms/AES$IvDecryptor, dev/whyoleg/cryptography/algorithms/AES$IvEncryptor, dev/whyoleg/cryptography/operations/Cipher { @@ -176,6 +188,10 @@ public abstract interface class dev/whyoleg/cryptography/algorithms/AES$IvDecryp public static synthetic fun decryptWithIv$suspendImpl (Ldev/whyoleg/cryptography/algorithms/AES$IvDecryptor;[B[BLkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun decryptWithIvBlocking (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/bytestring/ByteString; public abstract fun decryptWithIvBlocking ([B[B)[B + public fun decryptingSinkWithIv (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/RawSink;)Lkotlinx/io/RawSink; + public abstract fun decryptingSinkWithIv ([BLkotlinx/io/RawSink;)Lkotlinx/io/RawSink; + public fun decryptingSourceWithIv (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/RawSource;)Lkotlinx/io/RawSource; + public abstract fun decryptingSourceWithIv ([BLkotlinx/io/RawSource;)Lkotlinx/io/RawSource; } public abstract interface class dev/whyoleg/cryptography/algorithms/AES$IvEncryptor : dev/whyoleg/cryptography/operations/Encryptor { @@ -185,6 +201,10 @@ public abstract interface class dev/whyoleg/cryptography/algorithms/AES$IvEncryp public static synthetic fun encryptWithIv$suspendImpl (Ldev/whyoleg/cryptography/algorithms/AES$IvEncryptor;[B[BLkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun encryptWithIvBlocking (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/bytestring/ByteString; public abstract fun encryptWithIvBlocking ([B[B)[B + public fun encryptingSinkWithIv (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/RawSink;)Lkotlinx/io/RawSink; + public abstract fun encryptingSinkWithIv ([BLkotlinx/io/RawSink;)Lkotlinx/io/RawSink; + public fun encryptingSourceWithIv (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/RawSource;)Lkotlinx/io/RawSource; + public abstract fun encryptingSourceWithIv ([BLkotlinx/io/RawSource;)Lkotlinx/io/RawSource; } public abstract interface class dev/whyoleg/cryptography/algorithms/AES$Key : dev/whyoleg/cryptography/materials/key/EncodableKey { @@ -705,6 +725,12 @@ public abstract interface class dev/whyoleg/cryptography/operations/Authenticate public fun decryptBlocking (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/bytestring/ByteString; public fun decryptBlocking ([B)[B public abstract fun decryptBlocking ([B[B)[B + public fun decryptingSink (Lkotlinx/io/RawSink;)Lkotlinx/io/RawSink; + public fun decryptingSink (Lkotlinx/io/RawSink;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/RawSink; + public abstract fun decryptingSink (Lkotlinx/io/RawSink;[B)Lkotlinx/io/RawSink; + public fun decryptingSource (Lkotlinx/io/RawSource;)Lkotlinx/io/RawSource; + public fun decryptingSource (Lkotlinx/io/RawSource;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/RawSource; + public abstract fun decryptingSource (Lkotlinx/io/RawSource;[B)Lkotlinx/io/RawSource; } public abstract interface class dev/whyoleg/cryptography/operations/AuthenticatedEncryptor : dev/whyoleg/cryptography/operations/Encryptor { @@ -720,6 +746,12 @@ public abstract interface class dev/whyoleg/cryptography/operations/Authenticate public fun encryptBlocking (Lkotlinx/io/bytestring/ByteString;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/bytestring/ByteString; public fun encryptBlocking ([B)[B public abstract fun encryptBlocking ([B[B)[B + public fun encryptingSink (Lkotlinx/io/RawSink;)Lkotlinx/io/RawSink; + public fun encryptingSink (Lkotlinx/io/RawSink;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/RawSink; + public abstract fun encryptingSink (Lkotlinx/io/RawSink;[B)Lkotlinx/io/RawSink; + public fun encryptingSource (Lkotlinx/io/RawSource;)Lkotlinx/io/RawSource; + public fun encryptingSource (Lkotlinx/io/RawSource;Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/RawSource; + public abstract fun encryptingSource (Lkotlinx/io/RawSource;[B)Lkotlinx/io/RawSource; } public abstract interface class dev/whyoleg/cryptography/operations/Cipher : dev/whyoleg/cryptography/operations/Decryptor, dev/whyoleg/cryptography/operations/Encryptor { @@ -732,6 +764,8 @@ public abstract interface class dev/whyoleg/cryptography/operations/Decryptor { public static synthetic fun decrypt$suspendImpl (Ldev/whyoleg/cryptography/operations/Decryptor;[BLkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun decryptBlocking (Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/bytestring/ByteString; public abstract fun decryptBlocking ([B)[B + public abstract fun decryptingSink (Lkotlinx/io/RawSink;)Lkotlinx/io/RawSink; + public abstract fun decryptingSource (Lkotlinx/io/RawSource;)Lkotlinx/io/RawSource; } public abstract interface class dev/whyoleg/cryptography/operations/Encryptor { @@ -741,6 +775,8 @@ public abstract interface class dev/whyoleg/cryptography/operations/Encryptor { public static synthetic fun encrypt$suspendImpl (Ldev/whyoleg/cryptography/operations/Encryptor;[BLkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun encryptBlocking (Lkotlinx/io/bytestring/ByteString;)Lkotlinx/io/bytestring/ByteString; public abstract fun encryptBlocking ([B)[B + public abstract fun encryptingSink (Lkotlinx/io/RawSink;)Lkotlinx/io/RawSink; + public abstract fun encryptingSource (Lkotlinx/io/RawSource;)Lkotlinx/io/RawSource; } public abstract interface class dev/whyoleg/cryptography/operations/HashFunction : dev/whyoleg/cryptography/operations/UpdateFunction { diff --git a/cryptography-core/api/cryptography-core.klib.api b/cryptography-core/api/cryptography-core.klib.api index 9b70c0b7..4d860ce4 100644 --- a/cryptography-core/api/cryptography-core.klib.api +++ b/cryptography-core/api/cryptography-core.klib.api @@ -67,9 +67,15 @@ abstract interface <#A: dev.whyoleg.cryptography.algorithms/AES.Key> dev.whyoleg abstract interface IvAuthenticatedDecryptor : dev.whyoleg.cryptography.algorithms/AES.IvDecryptor, dev.whyoleg.cryptography.operations/AuthenticatedDecryptor { // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor|null[0] abstract fun decryptWithIvBlocking(kotlin/ByteArray, kotlin/ByteArray, kotlin/ByteArray?): kotlin/ByteArray // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor.decryptWithIvBlocking|decryptWithIvBlocking(kotlin.ByteArray;kotlin.ByteArray;kotlin.ByteArray?){}[0] + abstract fun decryptingSinkWithIv(kotlin/ByteArray, kotlinx.io/RawSink, kotlin/ByteArray?): kotlinx.io/RawSink // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor.decryptingSinkWithIv|decryptingSinkWithIv(kotlin.ByteArray;kotlinx.io.RawSink;kotlin.ByteArray?){}[0] + abstract fun decryptingSourceWithIv(kotlin/ByteArray, kotlinx.io/RawSource, kotlin/ByteArray?): kotlinx.io/RawSource // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor.decryptingSourceWithIv|decryptingSourceWithIv(kotlin.ByteArray;kotlinx.io.RawSource;kotlin.ByteArray?){}[0] open fun decryptWithIvBlocking(kotlin/ByteArray, kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor.decryptWithIvBlocking|decryptWithIvBlocking(kotlin.ByteArray;kotlin.ByteArray){}[0] open fun decryptWithIvBlocking(kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor.decryptWithIvBlocking|decryptWithIvBlocking(kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString){}[0] open fun decryptWithIvBlocking(kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString?): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor.decryptWithIvBlocking|decryptWithIvBlocking(kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString?){}[0] + open fun decryptingSinkWithIv(kotlin/ByteArray, kotlinx.io/RawSink): kotlinx.io/RawSink // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor.decryptingSinkWithIv|decryptingSinkWithIv(kotlin.ByteArray;kotlinx.io.RawSink){}[0] + open fun decryptingSinkWithIv(kotlinx.io.bytestring/ByteString, kotlinx.io/RawSink, kotlinx.io.bytestring/ByteString?): kotlinx.io/RawSink // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor.decryptingSinkWithIv|decryptingSinkWithIv(kotlinx.io.bytestring.ByteString;kotlinx.io.RawSink;kotlinx.io.bytestring.ByteString?){}[0] + open fun decryptingSourceWithIv(kotlin/ByteArray, kotlinx.io/RawSource): kotlinx.io/RawSource // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor.decryptingSourceWithIv|decryptingSourceWithIv(kotlin.ByteArray;kotlinx.io.RawSource){}[0] + open fun decryptingSourceWithIv(kotlinx.io.bytestring/ByteString, kotlinx.io/RawSource, kotlinx.io.bytestring/ByteString?): kotlinx.io/RawSource // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor.decryptingSourceWithIv|decryptingSourceWithIv(kotlinx.io.bytestring.ByteString;kotlinx.io.RawSource;kotlinx.io.bytestring.ByteString?){}[0] open suspend fun decryptWithIv(kotlin/ByteArray, kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor.decryptWithIv|decryptWithIv(kotlin.ByteArray;kotlin.ByteArray){}[0] open suspend fun decryptWithIv(kotlin/ByteArray, kotlin/ByteArray, kotlin/ByteArray?): kotlin/ByteArray // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor.decryptWithIv|decryptWithIv(kotlin.ByteArray;kotlin.ByteArray;kotlin.ByteArray?){}[0] open suspend fun decryptWithIv(kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedDecryptor.decryptWithIv|decryptWithIv(kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString){}[0] @@ -78,9 +84,15 @@ abstract interface <#A: dev.whyoleg.cryptography.algorithms/AES.Key> dev.whyoleg abstract interface IvAuthenticatedEncryptor : dev.whyoleg.cryptography.algorithms/AES.IvEncryptor, dev.whyoleg.cryptography.operations/AuthenticatedEncryptor { // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor|null[0] abstract fun encryptWithIvBlocking(kotlin/ByteArray, kotlin/ByteArray, kotlin/ByteArray?): kotlin/ByteArray // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor.encryptWithIvBlocking|encryptWithIvBlocking(kotlin.ByteArray;kotlin.ByteArray;kotlin.ByteArray?){}[0] + abstract fun encryptingSinkWithIv(kotlin/ByteArray, kotlinx.io/RawSink, kotlin/ByteArray?): kotlinx.io/RawSink // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor.encryptingSinkWithIv|encryptingSinkWithIv(kotlin.ByteArray;kotlinx.io.RawSink;kotlin.ByteArray?){}[0] + abstract fun encryptingSourceWithIv(kotlin/ByteArray, kotlinx.io/RawSource, kotlin/ByteArray?): kotlinx.io/RawSource // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor.encryptingSourceWithIv|encryptingSourceWithIv(kotlin.ByteArray;kotlinx.io.RawSource;kotlin.ByteArray?){}[0] open fun encryptWithIvBlocking(kotlin/ByteArray, kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor.encryptWithIvBlocking|encryptWithIvBlocking(kotlin.ByteArray;kotlin.ByteArray){}[0] open fun encryptWithIvBlocking(kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor.encryptWithIvBlocking|encryptWithIvBlocking(kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString){}[0] open fun encryptWithIvBlocking(kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString?): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor.encryptWithIvBlocking|encryptWithIvBlocking(kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString?){}[0] + open fun encryptingSinkWithIv(kotlin/ByteArray, kotlinx.io/RawSink): kotlinx.io/RawSink // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor.encryptingSinkWithIv|encryptingSinkWithIv(kotlin.ByteArray;kotlinx.io.RawSink){}[0] + open fun encryptingSinkWithIv(kotlinx.io.bytestring/ByteString, kotlinx.io/RawSink, kotlinx.io.bytestring/ByteString?): kotlinx.io/RawSink // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor.encryptingSinkWithIv|encryptingSinkWithIv(kotlinx.io.bytestring.ByteString;kotlinx.io.RawSink;kotlinx.io.bytestring.ByteString?){}[0] + open fun encryptingSourceWithIv(kotlin/ByteArray, kotlinx.io/RawSource): kotlinx.io/RawSource // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor.encryptingSourceWithIv|encryptingSourceWithIv(kotlin.ByteArray;kotlinx.io.RawSource){}[0] + open fun encryptingSourceWithIv(kotlinx.io.bytestring/ByteString, kotlinx.io/RawSource, kotlinx.io.bytestring/ByteString?): kotlinx.io/RawSource // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor.encryptingSourceWithIv|encryptingSourceWithIv(kotlinx.io.bytestring.ByteString;kotlinx.io.RawSource;kotlinx.io.bytestring.ByteString?){}[0] open suspend fun encryptWithIv(kotlin/ByteArray, kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor.encryptWithIv|encryptWithIv(kotlin.ByteArray;kotlin.ByteArray){}[0] open suspend fun encryptWithIv(kotlin/ByteArray, kotlin/ByteArray, kotlin/ByteArray?): kotlin/ByteArray // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor.encryptWithIv|encryptWithIv(kotlin.ByteArray;kotlin.ByteArray;kotlin.ByteArray?){}[0] open suspend fun encryptWithIv(kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.algorithms/AES.IvAuthenticatedEncryptor.encryptWithIv|encryptWithIv(kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString){}[0] @@ -91,14 +103,22 @@ abstract interface <#A: dev.whyoleg.cryptography.algorithms/AES.Key> dev.whyoleg abstract interface IvDecryptor : dev.whyoleg.cryptography.operations/Decryptor { // dev.whyoleg.cryptography.algorithms/AES.IvDecryptor|null[0] abstract fun decryptWithIvBlocking(kotlin/ByteArray, kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.algorithms/AES.IvDecryptor.decryptWithIvBlocking|decryptWithIvBlocking(kotlin.ByteArray;kotlin.ByteArray){}[0] + abstract fun decryptingSinkWithIv(kotlin/ByteArray, kotlinx.io/RawSink): kotlinx.io/RawSink // dev.whyoleg.cryptography.algorithms/AES.IvDecryptor.decryptingSinkWithIv|decryptingSinkWithIv(kotlin.ByteArray;kotlinx.io.RawSink){}[0] + abstract fun decryptingSourceWithIv(kotlin/ByteArray, kotlinx.io/RawSource): kotlinx.io/RawSource // dev.whyoleg.cryptography.algorithms/AES.IvDecryptor.decryptingSourceWithIv|decryptingSourceWithIv(kotlin.ByteArray;kotlinx.io.RawSource){}[0] open fun decryptWithIvBlocking(kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.algorithms/AES.IvDecryptor.decryptWithIvBlocking|decryptWithIvBlocking(kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString){}[0] + open fun decryptingSinkWithIv(kotlinx.io.bytestring/ByteString, kotlinx.io/RawSink): kotlinx.io/RawSink // dev.whyoleg.cryptography.algorithms/AES.IvDecryptor.decryptingSinkWithIv|decryptingSinkWithIv(kotlinx.io.bytestring.ByteString;kotlinx.io.RawSink){}[0] + open fun decryptingSourceWithIv(kotlinx.io.bytestring/ByteString, kotlinx.io/RawSource): kotlinx.io/RawSource // dev.whyoleg.cryptography.algorithms/AES.IvDecryptor.decryptingSourceWithIv|decryptingSourceWithIv(kotlinx.io.bytestring.ByteString;kotlinx.io.RawSource){}[0] open suspend fun decryptWithIv(kotlin/ByteArray, kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.algorithms/AES.IvDecryptor.decryptWithIv|decryptWithIv(kotlin.ByteArray;kotlin.ByteArray){}[0] open suspend fun decryptWithIv(kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.algorithms/AES.IvDecryptor.decryptWithIv|decryptWithIv(kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString){}[0] } abstract interface IvEncryptor : dev.whyoleg.cryptography.operations/Encryptor { // dev.whyoleg.cryptography.algorithms/AES.IvEncryptor|null[0] abstract fun encryptWithIvBlocking(kotlin/ByteArray, kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.algorithms/AES.IvEncryptor.encryptWithIvBlocking|encryptWithIvBlocking(kotlin.ByteArray;kotlin.ByteArray){}[0] + abstract fun encryptingSinkWithIv(kotlin/ByteArray, kotlinx.io/RawSink): kotlinx.io/RawSink // dev.whyoleg.cryptography.algorithms/AES.IvEncryptor.encryptingSinkWithIv|encryptingSinkWithIv(kotlin.ByteArray;kotlinx.io.RawSink){}[0] + abstract fun encryptingSourceWithIv(kotlin/ByteArray, kotlinx.io/RawSource): kotlinx.io/RawSource // dev.whyoleg.cryptography.algorithms/AES.IvEncryptor.encryptingSourceWithIv|encryptingSourceWithIv(kotlin.ByteArray;kotlinx.io.RawSource){}[0] open fun encryptWithIvBlocking(kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.algorithms/AES.IvEncryptor.encryptWithIvBlocking|encryptWithIvBlocking(kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString){}[0] + open fun encryptingSinkWithIv(kotlinx.io.bytestring/ByteString, kotlinx.io/RawSink): kotlinx.io/RawSink // dev.whyoleg.cryptography.algorithms/AES.IvEncryptor.encryptingSinkWithIv|encryptingSinkWithIv(kotlinx.io.bytestring.ByteString;kotlinx.io.RawSink){}[0] + open fun encryptingSourceWithIv(kotlinx.io.bytestring/ByteString, kotlinx.io/RawSource): kotlinx.io/RawSource // dev.whyoleg.cryptography.algorithms/AES.IvEncryptor.encryptingSourceWithIv|encryptingSourceWithIv(kotlinx.io.bytestring.ByteString;kotlinx.io.RawSource){}[0] open suspend fun encryptWithIv(kotlin/ByteArray, kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.algorithms/AES.IvEncryptor.encryptWithIv|encryptWithIv(kotlin.ByteArray;kotlin.ByteArray){}[0] open suspend fun encryptWithIv(kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.algorithms/AES.IvEncryptor.encryptWithIv|encryptWithIv(kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString){}[0] } @@ -553,9 +573,15 @@ abstract interface dev.whyoleg.cryptography.operations/AuthenticatedCipher : dev abstract interface dev.whyoleg.cryptography.operations/AuthenticatedDecryptor : dev.whyoleg.cryptography.operations/Decryptor { // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor|null[0] abstract fun decryptBlocking(kotlin/ByteArray, kotlin/ByteArray?): kotlin/ByteArray // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor.decryptBlocking|decryptBlocking(kotlin.ByteArray;kotlin.ByteArray?){}[0] + abstract fun decryptingSink(kotlinx.io/RawSink, kotlin/ByteArray?): kotlinx.io/RawSink // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor.decryptingSink|decryptingSink(kotlinx.io.RawSink;kotlin.ByteArray?){}[0] + abstract fun decryptingSource(kotlinx.io/RawSource, kotlin/ByteArray?): kotlinx.io/RawSource // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor.decryptingSource|decryptingSource(kotlinx.io.RawSource;kotlin.ByteArray?){}[0] open fun decryptBlocking(kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor.decryptBlocking|decryptBlocking(kotlin.ByteArray){}[0] open fun decryptBlocking(kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor.decryptBlocking|decryptBlocking(kotlinx.io.bytestring.ByteString){}[0] open fun decryptBlocking(kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString?): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor.decryptBlocking|decryptBlocking(kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString?){}[0] + open fun decryptingSink(kotlinx.io/RawSink): kotlinx.io/RawSink // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor.decryptingSink|decryptingSink(kotlinx.io.RawSink){}[0] + open fun decryptingSink(kotlinx.io/RawSink, kotlinx.io.bytestring/ByteString?): kotlinx.io/RawSink // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor.decryptingSink|decryptingSink(kotlinx.io.RawSink;kotlinx.io.bytestring.ByteString?){}[0] + open fun decryptingSource(kotlinx.io/RawSource): kotlinx.io/RawSource // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor.decryptingSource|decryptingSource(kotlinx.io.RawSource){}[0] + open fun decryptingSource(kotlinx.io/RawSource, kotlinx.io.bytestring/ByteString?): kotlinx.io/RawSource // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor.decryptingSource|decryptingSource(kotlinx.io.RawSource;kotlinx.io.bytestring.ByteString?){}[0] open suspend fun decrypt(kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor.decrypt|decrypt(kotlin.ByteArray){}[0] open suspend fun decrypt(kotlin/ByteArray, kotlin/ByteArray?): kotlin/ByteArray // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor.decrypt|decrypt(kotlin.ByteArray;kotlin.ByteArray?){}[0] open suspend fun decrypt(kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor.decrypt|decrypt(kotlinx.io.bytestring.ByteString){}[0] @@ -564,9 +590,15 @@ abstract interface dev.whyoleg.cryptography.operations/AuthenticatedDecryptor : abstract interface dev.whyoleg.cryptography.operations/AuthenticatedEncryptor : dev.whyoleg.cryptography.operations/Encryptor { // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor|null[0] abstract fun encryptBlocking(kotlin/ByteArray, kotlin/ByteArray?): kotlin/ByteArray // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor.encryptBlocking|encryptBlocking(kotlin.ByteArray;kotlin.ByteArray?){}[0] + abstract fun encryptingSink(kotlinx.io/RawSink, kotlin/ByteArray?): kotlinx.io/RawSink // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor.encryptingSink|encryptingSink(kotlinx.io.RawSink;kotlin.ByteArray?){}[0] + abstract fun encryptingSource(kotlinx.io/RawSource, kotlin/ByteArray?): kotlinx.io/RawSource // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor.encryptingSource|encryptingSource(kotlinx.io.RawSource;kotlin.ByteArray?){}[0] open fun encryptBlocking(kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor.encryptBlocking|encryptBlocking(kotlin.ByteArray){}[0] open fun encryptBlocking(kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor.encryptBlocking|encryptBlocking(kotlinx.io.bytestring.ByteString){}[0] open fun encryptBlocking(kotlinx.io.bytestring/ByteString, kotlinx.io.bytestring/ByteString?): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor.encryptBlocking|encryptBlocking(kotlinx.io.bytestring.ByteString;kotlinx.io.bytestring.ByteString?){}[0] + open fun encryptingSink(kotlinx.io/RawSink): kotlinx.io/RawSink // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor.encryptingSink|encryptingSink(kotlinx.io.RawSink){}[0] + open fun encryptingSink(kotlinx.io/RawSink, kotlinx.io.bytestring/ByteString?): kotlinx.io/RawSink // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor.encryptingSink|encryptingSink(kotlinx.io.RawSink;kotlinx.io.bytestring.ByteString?){}[0] + open fun encryptingSource(kotlinx.io/RawSource): kotlinx.io/RawSource // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor.encryptingSource|encryptingSource(kotlinx.io.RawSource){}[0] + open fun encryptingSource(kotlinx.io/RawSource, kotlinx.io.bytestring/ByteString?): kotlinx.io/RawSource // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor.encryptingSource|encryptingSource(kotlinx.io.RawSource;kotlinx.io.bytestring.ByteString?){}[0] open suspend fun encrypt(kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor.encrypt|encrypt(kotlin.ByteArray){}[0] open suspend fun encrypt(kotlin/ByteArray, kotlin/ByteArray?): kotlin/ByteArray // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor.encrypt|encrypt(kotlin.ByteArray;kotlin.ByteArray?){}[0] open suspend fun encrypt(kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.operations/AuthenticatedEncryptor.encrypt|encrypt(kotlinx.io.bytestring.ByteString){}[0] @@ -577,6 +609,8 @@ abstract interface dev.whyoleg.cryptography.operations/Cipher : dev.whyoleg.cryp abstract interface dev.whyoleg.cryptography.operations/Decryptor { // dev.whyoleg.cryptography.operations/Decryptor|null[0] abstract fun decryptBlocking(kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.operations/Decryptor.decryptBlocking|decryptBlocking(kotlin.ByteArray){}[0] + abstract fun decryptingSink(kotlinx.io/RawSink): kotlinx.io/RawSink // dev.whyoleg.cryptography.operations/Decryptor.decryptingSink|decryptingSink(kotlinx.io.RawSink){}[0] + abstract fun decryptingSource(kotlinx.io/RawSource): kotlinx.io/RawSource // dev.whyoleg.cryptography.operations/Decryptor.decryptingSource|decryptingSource(kotlinx.io.RawSource){}[0] open fun decryptBlocking(kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.operations/Decryptor.decryptBlocking|decryptBlocking(kotlinx.io.bytestring.ByteString){}[0] open suspend fun decrypt(kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.operations/Decryptor.decrypt|decrypt(kotlin.ByteArray){}[0] open suspend fun decrypt(kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.operations/Decryptor.decrypt|decrypt(kotlinx.io.bytestring.ByteString){}[0] @@ -584,6 +618,8 @@ abstract interface dev.whyoleg.cryptography.operations/Decryptor { // dev.whyole abstract interface dev.whyoleg.cryptography.operations/Encryptor { // dev.whyoleg.cryptography.operations/Encryptor|null[0] abstract fun encryptBlocking(kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.operations/Encryptor.encryptBlocking|encryptBlocking(kotlin.ByteArray){}[0] + abstract fun encryptingSink(kotlinx.io/RawSink): kotlinx.io/RawSink // dev.whyoleg.cryptography.operations/Encryptor.encryptingSink|encryptingSink(kotlinx.io.RawSink){}[0] + abstract fun encryptingSource(kotlinx.io/RawSource): kotlinx.io/RawSource // dev.whyoleg.cryptography.operations/Encryptor.encryptingSource|encryptingSource(kotlinx.io.RawSource){}[0] open fun encryptBlocking(kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.operations/Encryptor.encryptBlocking|encryptBlocking(kotlinx.io.bytestring.ByteString){}[0] open suspend fun encrypt(kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.operations/Encryptor.encrypt|encrypt(kotlin.ByteArray){}[0] open suspend fun encrypt(kotlinx.io.bytestring/ByteString): kotlinx.io.bytestring/ByteString // dev.whyoleg.cryptography.operations/Encryptor.encrypt|encrypt(kotlinx.io.bytestring.ByteString){}[0] diff --git a/cryptography-core/src/commonMain/kotlin/algorithms/AES.kt b/cryptography-core/src/commonMain/kotlin/algorithms/AES.kt index 25b56005..9d30e3d1 100644 --- a/cryptography-core/src/commonMain/kotlin/algorithms/AES.kt +++ b/cryptography-core/src/commonMain/kotlin/algorithms/AES.kt @@ -9,6 +9,7 @@ import dev.whyoleg.cryptography.BinarySize.Companion.bits import dev.whyoleg.cryptography.algorithms.symmetric.* import dev.whyoleg.cryptography.materials.key.* import dev.whyoleg.cryptography.operations.* +import kotlinx.io.* import kotlinx.io.bytestring.* @SubclassOptInRequired(CryptographyProviderApi::class) @@ -105,6 +106,24 @@ public interface AES : CryptographyAlgorithm { public fun encryptWithIvBlocking(iv: ByteString, plaintext: ByteString): ByteString { return encryptWithIvBlocking(iv.asByteArray(), plaintext.asByteArray()).asByteString() } + + + @DelicateCryptographyApi + public fun encryptingSourceWithIv(iv: ByteArray, plaintext: RawSource): RawSource + + @DelicateCryptographyApi + public fun encryptingSourceWithIv(iv: ByteString, plaintext: RawSource): RawSource { + return encryptingSourceWithIv(iv.asByteArray(), plaintext) + } + + + @DelicateCryptographyApi + public fun encryptingSinkWithIv(iv: ByteArray, ciphertext: RawSink): RawSink + + @DelicateCryptographyApi + public fun encryptingSinkWithIv(iv: ByteString, ciphertext: RawSink): RawSink { + return encryptingSinkWithIv(iv.asByteArray(), ciphertext) + } } @SubclassOptInRequired(CryptographyProviderApi::class) @@ -126,6 +145,24 @@ public interface AES : CryptographyAlgorithm { public fun decryptWithIvBlocking(iv: ByteString, ciphertext: ByteString): ByteString { return decryptWithIvBlocking(iv.asByteArray(), ciphertext.asByteArray()).asByteString() } + + + @DelicateCryptographyApi + public fun decryptingSourceWithIv(iv: ByteArray, ciphertext: RawSource): RawSource + + @DelicateCryptographyApi + public fun decryptingSourceWithIv(iv: ByteString, ciphertext: RawSource): RawSource { + return decryptingSourceWithIv(iv.asByteArray(), ciphertext) + } + + + @DelicateCryptographyApi + public fun decryptingSinkWithIv(iv: ByteArray, plaintext: RawSink): RawSink + + @DelicateCryptographyApi + public fun decryptingSinkWithIv(iv: ByteString, plaintext: RawSink): RawSink { + return decryptingSinkWithIv(iv.asByteArray(), plaintext) + } } @SubclassOptInRequired(CryptographyProviderApi::class) @@ -170,6 +207,34 @@ public interface AES : CryptographyAlgorithm { public fun encryptWithIvBlocking(iv: ByteString, plaintext: ByteString, associatedData: ByteString?): ByteString { return encryptWithIvBlocking(iv.asByteArray(), plaintext.asByteArray(), associatedData?.toByteArray()).asByteString() } + + + @DelicateCryptographyApi + override fun encryptingSourceWithIv(iv: ByteArray, plaintext: RawSource): RawSource { + return encryptingSourceWithIv(iv, plaintext, null) + } + + @DelicateCryptographyApi + public fun encryptingSourceWithIv(iv: ByteArray, plaintext: RawSource, associatedData: ByteArray?): RawSource + + @DelicateCryptographyApi + public fun encryptingSourceWithIv(iv: ByteString, plaintext: RawSource, associatedData: ByteString?): RawSource { + return encryptingSourceWithIv(iv.asByteArray(), plaintext, associatedData?.asByteArray()) + } + + + @DelicateCryptographyApi + override fun encryptingSinkWithIv(iv: ByteArray, ciphertext: RawSink): RawSink { + return encryptingSinkWithIv(iv, ciphertext, null) + } + + @DelicateCryptographyApi + public fun encryptingSinkWithIv(iv: ByteArray, ciphertext: RawSink, associatedData: ByteArray?): RawSink + + @DelicateCryptographyApi + public fun encryptingSinkWithIv(iv: ByteString, ciphertext: RawSink, associatedData: ByteString?): RawSink { + return encryptingSinkWithIv(iv.asByteArray(), ciphertext, associatedData?.toByteArray()) + } } @SubclassOptInRequired(CryptographyProviderApi::class) @@ -212,5 +277,33 @@ public interface AES : CryptographyAlgorithm { public fun decryptWithIvBlocking(iv: ByteString, ciphertext: ByteString, associatedData: ByteString?): ByteString { return decryptWithIvBlocking(iv.asByteArray(), ciphertext.asByteArray(), associatedData?.toByteArray()).asByteString() } + + + @DelicateCryptographyApi + override fun decryptingSourceWithIv(iv: ByteArray, ciphertext: RawSource): RawSource { + return decryptingSourceWithIv(iv, ciphertext, null) + } + + @DelicateCryptographyApi + public fun decryptingSourceWithIv(iv: ByteArray, plaintext: RawSource, associatedData: ByteArray?): RawSource + + @DelicateCryptographyApi + public fun decryptingSourceWithIv(iv: ByteString, plaintext: RawSource, associatedData: ByteString?): RawSource { + return decryptingSourceWithIv(iv.asByteArray(), plaintext, associatedData?.asByteArray()) + } + + + @DelicateCryptographyApi + override fun decryptingSinkWithIv(iv: ByteArray, plaintext: RawSink): RawSink { + return decryptingSinkWithIv(iv, plaintext, null) + } + + @DelicateCryptographyApi + public fun decryptingSinkWithIv(iv: ByteArray, ciphertext: RawSink, associatedData: ByteArray?): RawSink + + @DelicateCryptographyApi + public fun decryptingSinkWithIv(iv: ByteString, ciphertext: RawSink, associatedData: ByteString?): RawSink { + return decryptingSinkWithIv(iv.asByteArray(), ciphertext, associatedData?.toByteArray()) + } } } diff --git a/cryptography-core/src/commonMain/kotlin/operations/AuthenticatedCipher.kt b/cryptography-core/src/commonMain/kotlin/operations/AuthenticatedCipher.kt index fea79d8a..3eab4502 100644 --- a/cryptography-core/src/commonMain/kotlin/operations/AuthenticatedCipher.kt +++ b/cryptography-core/src/commonMain/kotlin/operations/AuthenticatedCipher.kt @@ -5,44 +5,121 @@ package dev.whyoleg.cryptography.operations import dev.whyoleg.cryptography.* +import kotlinx.io.* import kotlinx.io.bytestring.* @SubclassOptInRequired(CryptographyProviderApi::class) public interface AuthenticatedCipher : Cipher, AuthenticatedEncryptor, AuthenticatedDecryptor - @SubclassOptInRequired(CryptographyProviderApi::class) public interface AuthenticatedEncryptor : Encryptor { - public suspend fun encrypt(plaintext: ByteArray, associatedData: ByteArray?): ByteArray = encryptBlocking(plaintext, associatedData) + public override suspend fun encrypt(plaintext: ByteArray): ByteArray { + return encrypt(plaintext, null) + } + + public override suspend fun encrypt(plaintext: ByteString): ByteString { + return encrypt(plaintext, null) + } + + public suspend fun encrypt(plaintext: ByteArray, associatedData: ByteArray?): ByteArray { + return encryptBlocking(plaintext, associatedData) + } + + public suspend fun encrypt(plaintext: ByteString, associatedData: ByteString?): ByteString { + return encrypt(plaintext.asByteArray(), associatedData?.asByteArray()).asByteString() + } + + + public override fun encryptBlocking(plaintext: ByteArray): ByteArray { + return encryptBlocking(plaintext, null) + } + + public override fun encryptBlocking(plaintext: ByteString): ByteString { + return encryptBlocking(plaintext, null) + } + public fun encryptBlocking(plaintext: ByteArray, associatedData: ByteArray?): ByteArray - public override suspend fun encrypt(plaintext: ByteArray): ByteArray = encrypt(plaintext, null) - public override fun encryptBlocking(plaintext: ByteArray): ByteArray = encryptBlocking(plaintext, null) + public fun encryptBlocking(plaintext: ByteString, associatedData: ByteString?): ByteString { + return encryptBlocking(plaintext.asByteArray(), associatedData?.asByteArray()).asByteString() + } + + + public override fun encryptingSource(plaintext: RawSource): RawSource { + return encryptingSource(plaintext, null as ByteArray?) + } + + public fun encryptingSource(plaintext: RawSource, associatedData: ByteArray?): RawSource + + public fun encryptingSource(plaintext: RawSource, associatedData: ByteString?): RawSource { + return encryptingSource(plaintext, associatedData?.asByteArray()) + } + - public suspend fun encrypt(plaintext: ByteString, associatedData: ByteString?): ByteString = - encrypt(plaintext.asByteArray(), associatedData?.asByteArray()).asByteString() + public override fun encryptingSink(ciphertext: RawSink): RawSink { + return encryptingSink(ciphertext, null as ByteArray?) + } - public fun encryptBlocking(plaintext: ByteString, associatedData: ByteString?): ByteString = - encryptBlocking(plaintext.asByteArray(), associatedData?.asByteArray()).asByteString() + public fun encryptingSink(ciphertext: RawSink, associatedData: ByteArray?): RawSink - public override suspend fun encrypt(plaintext: ByteString): ByteString = encrypt(plaintext, null) - public override fun encryptBlocking(plaintext: ByteString): ByteString = encryptBlocking(plaintext, null) + public fun encryptingSink(ciphertext: RawSink, associatedData: ByteString?): RawSink { + return encryptingSink(ciphertext, associatedData?.asByteArray()) + } } @SubclassOptInRequired(CryptographyProviderApi::class) public interface AuthenticatedDecryptor : Decryptor { - public suspend fun decrypt(ciphertext: ByteArray, associatedData: ByteArray?): ByteArray = decryptBlocking(ciphertext, associatedData) + + public override suspend fun decrypt(ciphertext: ByteArray): ByteArray { + return decrypt(ciphertext, null) + } + + public override suspend fun decrypt(ciphertext: ByteString): ByteString { + return decrypt(ciphertext, null) + } + + public suspend fun decrypt(ciphertext: ByteArray, associatedData: ByteArray?): ByteArray { + return decryptBlocking(ciphertext, associatedData) + } + + public suspend fun decrypt(ciphertext: ByteString, associatedData: ByteString?): ByteString { + return decrypt(ciphertext.asByteArray(), associatedData?.asByteArray()).asByteString() + } + + + public override fun decryptBlocking(ciphertext: ByteArray): ByteArray { + return decryptBlocking(ciphertext, null) + } + + public override fun decryptBlocking(ciphertext: ByteString): ByteString { + return decryptBlocking(ciphertext, null) + } + public fun decryptBlocking(ciphertext: ByteArray, associatedData: ByteArray?): ByteArray - public override suspend fun decrypt(ciphertext: ByteArray): ByteArray = decrypt(ciphertext, null) - public override fun decryptBlocking(ciphertext: ByteArray): ByteArray = decryptBlocking(ciphertext, null) + public fun decryptBlocking(ciphertext: ByteString, associatedData: ByteString?): ByteString { + return decryptBlocking(ciphertext.asByteArray(), associatedData?.asByteArray()).asByteString() + } + + + public override fun decryptingSource(ciphertext: RawSource): RawSource { + return decryptingSource(ciphertext, null as ByteArray?) + } + + public fun decryptingSource(ciphertext: RawSource, associatedData: ByteArray?): RawSource + + public fun decryptingSource(ciphertext: RawSource, associatedData: ByteString?): RawSource { + return decryptingSource(ciphertext, associatedData?.asByteArray()) + } + - public suspend fun decrypt(ciphertext: ByteString, associatedData: ByteString?): ByteString = - decrypt(ciphertext.asByteArray(), associatedData?.asByteArray()).asByteString() + public override fun decryptingSink(plaintext: RawSink): RawSink { + return decryptingSink(plaintext, null as ByteArray?) + } - public fun decryptBlocking(ciphertext: ByteString, associatedData: ByteString?): ByteString = - decryptBlocking(ciphertext.asByteArray(), associatedData?.asByteArray()).asByteString() + public fun decryptingSink(plaintext: RawSink, associatedData: ByteArray?): RawSink - public override suspend fun decrypt(ciphertext: ByteString): ByteString = decrypt(ciphertext, null) - public override fun decryptBlocking(ciphertext: ByteString): ByteString = decryptBlocking(ciphertext, null) + public fun decryptingSink(plaintext: RawSink, associatedData: ByteString?): RawSink { + return decryptingSink(plaintext, associatedData?.asByteArray()) + } } diff --git a/cryptography-core/src/commonMain/kotlin/operations/Cipher.kt b/cryptography-core/src/commonMain/kotlin/operations/Cipher.kt index 42cc58fd..01faf4ad 100644 --- a/cryptography-core/src/commonMain/kotlin/operations/Cipher.kt +++ b/cryptography-core/src/commonMain/kotlin/operations/Cipher.kt @@ -5,6 +5,7 @@ package dev.whyoleg.cryptography.operations import dev.whyoleg.cryptography.* +import kotlinx.io.* import kotlinx.io.bytestring.* @SubclassOptInRequired(CryptographyProviderApi::class) @@ -12,18 +13,42 @@ public interface Cipher : Encryptor, Decryptor @SubclassOptInRequired(CryptographyProviderApi::class) public interface Encryptor { - public suspend fun encrypt(plaintext: ByteArray): ByteArray = encryptBlocking(plaintext) + public suspend fun encrypt(plaintext: ByteArray): ByteArray { + return encryptBlocking(plaintext) + } + + public suspend fun encrypt(plaintext: ByteString): ByteString { + return encrypt(plaintext.asByteArray()).asByteString() + } + public fun encryptBlocking(plaintext: ByteArray): ByteArray - public suspend fun encrypt(plaintext: ByteString): ByteString = encrypt(plaintext.asByteArray()).asByteString() - public fun encryptBlocking(plaintext: ByteString): ByteString = encryptBlocking(plaintext.asByteArray()).asByteString() + public fun encryptBlocking(plaintext: ByteString): ByteString { + return encryptBlocking(plaintext.asByteArray()).asByteString() + } + + public fun encryptingSource(plaintext: RawSource): RawSource + + public fun encryptingSink(ciphertext: RawSink): RawSink } @SubclassOptInRequired(CryptographyProviderApi::class) public interface Decryptor { - public suspend fun decrypt(ciphertext: ByteArray): ByteArray = decryptBlocking(ciphertext) + public suspend fun decrypt(ciphertext: ByteArray): ByteArray { + return decryptBlocking(ciphertext) + } + + public suspend fun decrypt(ciphertext: ByteString): ByteString { + return decrypt(ciphertext.asByteArray()).asByteString() + } + public fun decryptBlocking(ciphertext: ByteArray): ByteArray - public suspend fun decrypt(ciphertext: ByteString): ByteString = decrypt(ciphertext.asByteArray()).asByteString() - public fun decryptBlocking(ciphertext: ByteString): ByteString = decryptBlocking(ciphertext.asByteArray()).asByteString() + public fun decryptBlocking(ciphertext: ByteString): ByteString { + return decryptBlocking(ciphertext.asByteArray()).asByteString() + } + + public fun decryptingSource(ciphertext: RawSource): RawSource + + public fun decryptingSink(plaintext: RawSink): RawSink }