Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cloning of encryptor/decryptor #35

Merged

Conversation

lgoldstein
Copy link

The expected use-case is as follows:

  • User sets up a "template" encryptor/decryptor - cipher, compression, keys, etc.
  • There are several threads that according to some input and/or business logic apply the template with some minor changes - e.g., different symmetric password, different compression, with/out armored headers, etc.
  • Since an encryptor/decryptor is stateful, the threads cannot share the same instance so they need to create a new one to be used locally by each thread.
  • By providing clone() method implementation we simplify the code since threads do not need to re-initialize the encryptor/decryptor from scratch (which could be time consuming) - only modify the specific settings they need locally
  • Furthermore, by using the clone() method we ensure that users don't have to copy each setting individually from the template to the local copy - thus avoiding possible errors by forgetting to copy a field, failing to create a new copy for shared compound objects references (e.g., Ring, armored headers, etc.) or not keeping up with future changes by not copying new fields we might add.

@justinludwig
Copy link
Owner

Thanks -- looks good! I think you might also want to implement Cloneable for Key and Subkey, too, though. Otherwise, if you add keys to an encryptor/decryptor ring before you clone it, you'll end up with multiple encryptor/decryptors sharing the same subkey instances -- which could would cause problems if clearSecrets() is called on one encryptor/decryptor while other encryptors/decryptors are still using a shared subkey instance (as it will clear the subkey's extracted private key material, as well as any passphrase that could be use to extract it again).

@lgoldstein
Copy link
Author

Good catch - done.

@justinludwig justinludwig merged commit a3be72d into justinludwig:master Aug 13, 2021
@lgoldstein lgoldstein deleted the clone-encryptor-decryptor branch August 14, 2021 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants