Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Creating only one IAuthenticatedEncryptor per IKey #221

Merged
merged 1 commit into from
Apr 24, 2017

Conversation

ajaybhargavb
Copy link
Contributor

Issue - #220

Problem:
We should be creating only one IAuthenticatedEncryptor instance per key. After #134, we now have multiple instances being created.

Solution:
Brought back CreateEncryptorInstance() on IKey

Why was this needed?
Currently IKey and IAuthenticatedEncryptor creation are decoupled. Because of that there was no way to associate an encryptor instance with a key. Having CreateEncryptorInstance() on IKey lets us use the same encryptor instance across multiple calls.

@rynowak

}
}

return _encryptor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be thread safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and we already do a lock here https://github.com/aspnet/DataProtection/pull/221/files#diff-3dda400bcdb5a80421cdd26389311c63R77. The other places that we call this are just for Debug.Assert and we don't use those objects that are created. This has been the same since before the refactor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still haven't really answered this. If the invariant that we only create one is important, this code isn't correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spoke offline. This lock here was added as a perf optimization and we don't need to make changes to this.

/// to and decrypt data from this key.
/// </summary>
/// <returns>An <see cref="IAuthenticatedEncryptor"/>.</returns>
IAuthenticatedEncryptor CreateEncryptorInstance();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called CreateEncryptor

@rynowak
Copy link
Member

rynowak commented Apr 10, 2017

I'm not sure I understand the problem that's being solved here. This change basically reverts the design, now instead of being data the key is a factory

@ajaybhargavb
Copy link
Contributor Author

Spoke offline. We need CreateEncryptorInstance() on IKey because there is no other way to associate an encryptor instance with a key.

@ajaybhargavb ajaybhargavb force-pushed the ajbaaska/fix-encryptor branch from 702e465 to e55da74 Compare April 22, 2017 02:36
@ajaybhargavb
Copy link
Contributor Author

🆙 📅 No longer in design

@ajaybhargavb ajaybhargavb changed the title [Design] Creating only one IAuthenticatedEncryptor per IKey Creating only one IAuthenticatedEncryptor per IKey Apr 22, 2017
@ajaybhargavb ajaybhargavb force-pushed the ajbaaska/fix-encryptor branch from e55da74 to c959795 Compare April 24, 2017 17:47
@ajaybhargavb ajaybhargavb merged commit c959795 into dev Apr 24, 2017
@ajaybhargavb ajaybhargavb deleted the ajbaaska/fix-encryptor branch April 24, 2017 17:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants