Repository: commons-crypto Updated Branches: refs/heads/master ec4150fe3 -> eee2f509c
CRYPTO-135: Add comment about need for blocking sinks. Implementing non-blocking semantics in the WritableByteChannel portion of CryptoOutputStream is non-trivial. The existing options require weird return values and thus require the caller to know they're writing to a CryptoOutputStream and not a regular byte channel. In that case, it's better for the app to just not use the stream implementation and use the ciphers directly, since that gives the code better control of encryption. This change just adds comments to warn API users that the output streams are expected to be used only with blocking I/O. Closes #87 Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/eee2f509 Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/eee2f509 Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/eee2f509 Branch: refs/heads/master Commit: eee2f509cef33ff6d56dc4faaecc551b4e7ce077 Parents: ec4150f Author: Marcelo Vanzin <[email protected]> Authored: Wed Oct 3 10:48:14 2018 -0700 Committer: Marcelo Vanzin <[email protected]> Committed: Thu Oct 4 09:18:07 2018 -0700 ---------------------------------------------------------------------- .../org/apache/commons/crypto/stream/CryptoOutputStream.java | 4 ++++ .../apache/commons/crypto/stream/CtrCryptoOutputStream.java | 6 ++++++ 2 files changed, 10 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/eee2f509/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java b/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java index 4246713..b92d975 100644 --- a/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java +++ b/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java @@ -43,6 +43,10 @@ import org.apache.commons.crypto.utils.Utils; * {@link CryptoOutputStream} encrypts data and writes to the under layer * output. It supports any mode of operations such as AES CBC/CTR/GCM mode in * concept. It is not thread-safe. + * <p> + * This class should only be used with blocking sinks. Using this class to wrap + * a non-blocking sink may lead to high CPU usage. + * </p> */ public class CryptoOutputStream extends OutputStream implements http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/eee2f509/src/main/java/org/apache/commons/crypto/stream/CtrCryptoOutputStream.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoOutputStream.java b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoOutputStream.java index c05b0c0..958d1a5 100644 --- a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoOutputStream.java +++ b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoOutputStream.java @@ -48,7 +48,13 @@ import org.apache.commons.crypto.utils.Utils; * counter = base + pos/(algorithm blocksize); padding = pos%(algorithm * blocksize); * </p> + * <p> * The underlying stream offset is maintained as state. + * </p> + * <p> + * This class should only be used with blocking sinks. Using this class to wrap + * a non-blocking sink may lead to high CPU usage. + * </p> */ public class CtrCryptoOutputStream extends CryptoOutputStream { /**
