aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2024-09-28 23:35:54 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2024-09-28 23:35:54 +0530
commit5803f0244a5669b10f09b3f75fe3493143f0aff3 (patch)
tree7ad58e9dc3726afaafe7b1799819f2814013a8dd
parent7e1ed55ab7f4650ac0825e63bd7d2defd968faba (diff)
Reapply "refactor: use `Closeable#use` extension where applicable"
This reverts commit 04f4b9804f10e4724bac22d40bf01711ff708533.
-rw-r--r--app/src/main/java/app/passwordstore/util/services/PasswordExportService.kt5
-rw-r--r--crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt6
2 files changed, 3 insertions, 8 deletions
diff --git a/app/src/main/java/app/passwordstore/util/services/PasswordExportService.kt b/app/src/main/java/app/passwordstore/util/services/PasswordExportService.kt
index 854071f2..c74c3f0e 100644
--- a/app/src/main/java/app/passwordstore/util/services/PasswordExportService.kt
+++ b/app/src/main/java/app/passwordstore/util/services/PasswordExportService.kt
@@ -89,10 +89,7 @@ class PasswordExportService : Service() {
val destOutputStream = contentResolver.openOutputStream(targetPasswordFile.uri)
if (destOutputStream != null && sourceInputStream != null) {
- sourceInputStream.copyTo(destOutputStream, 1024)
-
- sourceInputStream.close()
- destOutputStream.close()
+ sourceInputStream.use { source -> destOutputStream.use { dest -> source.copyTo(dest) } }
}
}
}
diff --git a/crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt b/crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt
index 91826001..4a800129 100644
--- a/crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt
+++ b/crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt
@@ -65,8 +65,7 @@ public class PGPainlessCryptoHandler @Inject constructor() :
.addDecryptionKeys(keyringCollection, protector)
.addDecryptionPassphrase(Passphrase.fromPassword(passphrase))
)
- Streams.pipeAll(decryptionStream, outputStream)
- decryptionStream.close()
+ decryptionStream.use { Streams.pipeAll(it, outputStream) }
return@runCatching
}
.mapError { error ->
@@ -121,8 +120,7 @@ public class PGPainlessCryptoHandler @Inject constructor() :
.setAsciiArmor(options.isOptionEnabled(PGPEncryptOptions.ASCII_ARMOR))
val encryptionStream =
PGPainless.encryptAndOrSign().onOutputStream(outputStream).withOptions(producerOptions)
- Streams.pipeAll(plaintextStream, encryptionStream)
- encryptionStream.close()
+ encryptionStream.use { Streams.pipeAll(plaintextStream, it) }
val result = encryptionStream.result
publicKeyRingCollection.forEach { keyRing ->
require(result.isEncryptedFor(keyRing)) {