Kroppeb
09/09/2019, 4:58 PMstart
function
class EncryptionStep{
var key: SecretKey? = null
val input: ByteWriteChannel get() = _input
val output: ByteReadChannel get() = _output
private val _input = ByteChannel()
private val _output = ByteChannel()
@UseExperimental(InternalAPI::class)
fun CoroutineScope.start(encrypted: Pair<ByteReadChannel, ByteWriteChannel>) {
launch {
_input.read{
runBlocking{
when(val key = key){
null -> encrypted.second.writeAvailable(it)
else -> encrypted.second.writeAvailable(encryptData(key, it.moveToByteArray()))
}
}
}
}
}
}
fun CoroutineScope.encryptionStep(encrypted: Pair<ByteReadChannel, ByteWriteChannel>): EncryptionStep {
val step = EncryptionStep()
with(step){
start(encrypted)
}
return step
}
Dominaezzz
09/09/2019, 6:33 PMrunBlocking
?CoroutineScope
you should return some Job object.Kroppeb
09/09/2019, 10:04 PM