public void ParameterizedTests( IEnvelopeEncryption <byte[]> envelopeEncryptionJson, Mock <IMetastore <JObject> > metastore, KeyState cacheIK, KeyState metaIK, KeyState cacheSK, KeyState metaSK, Partition partition) { using (Session <JObject, byte[]> sessionJsonImpl = new SessionJsonImpl <byte[]>(envelopeEncryptionJson)) { EncryptMetastoreInteractions encryptMetastoreInteractions = new EncryptMetastoreInteractions(cacheIK, metaIK, cacheSK, metaSK); DecryptMetastoreInteractions decryptMetastoreInteractions = new DecryptMetastoreInteractions(cacheIK, cacheSK); // encrypt with library object(sessionJsonImpl) byte[] encryptedPayload = sessionJsonImpl.Encrypt(payload); Assert.NotNull(encryptedPayload); VerifyEncryptFlow(metastore, encryptMetastoreInteractions, partition); metastore.Invocations.Clear(); JObject decryptedPayload = sessionJsonImpl.Decrypt(encryptedPayload); VerifyDecryptFlow(metastore, decryptMetastoreInteractions, partition); Assert.True(JToken.DeepEquals(payload, decryptedPayload)); } }
public void ParameterizedTests( IEnvelopeEncryption <byte[]> envelopeEncryptionJson, Mock <MemoryPersistenceImpl <JObject> > metastorePersistence, KeyState cacheIK, KeyState metaIK, KeyState cacheSK, KeyState metaSK, AppEncryptionPartition appEncryptionPartition) { using (AppEncryption <JObject, byte[]> appEncryptionJsonImpl = new AppEncryptionJsonImpl <byte[]>(envelopeEncryptionJson)) { EncryptMetastoreInteractions encryptMetastoreInteractions = new EncryptMetastoreInteractions(cacheIK, metaIK, cacheSK, metaSK); DecryptMetastoreInteractions decryptMetastoreInteractions = new DecryptMetastoreInteractions(cacheIK, cacheSK); // encrypt with library object(appEncryptionJsonImpl) byte[] encryptedPayload = appEncryptionJsonImpl.Encrypt(payload); Assert.NotNull(encryptedPayload); VerifyEncryptFlow(metastorePersistence, encryptMetastoreInteractions, appEncryptionPartition); metastorePersistence.Reset(); JObject decryptedPayload = appEncryptionJsonImpl.Decrypt(encryptedPayload); VerifyDecryptFlow(metastorePersistence, decryptMetastoreInteractions, appEncryptionPartition); Assert.True(JToken.DeepEquals(payload, decryptedPayload)); } }
private void VerifyDecryptFlow( Mock <IMetastore <JObject> > metastore, DecryptMetastoreInteractions metastoreInteractions, Partition partition) { // If IK is loaded from metastore if (metastoreInteractions.ShouldLoadIK()) { metastore.Verify( x => x.Load(partition.IntermediateKeyId, It.IsAny <DateTimeOffset>()), Times.Once); } // If SK is loaded from metastore if (metastoreInteractions.ShouldLoadSK()) { metastore.Verify( x => x.Load(partition.SystemKeyId, It.IsAny <DateTimeOffset>()), Times.Once); } }
private void VerifyDecryptFlow( Mock <MemoryPersistenceImpl <JObject> > metastorePersistence, DecryptMetastoreInteractions metastoreInteractions, AppEncryptionPartition appEncryptionPartition) { // If IK is loaded from metastore if (metastoreInteractions.ShouldLoadIK()) { metastorePersistence.Verify( x => x.Load(appEncryptionPartition.IntermediateKeyId, It.IsAny <DateTimeOffset>()), Times.Once); } // If SK is loaded from metastore if (metastoreInteractions.ShouldLoadSK()) { metastorePersistence.Verify( x => x.Load(appEncryptionPartition.SystemKeyId, It.IsAny <DateTimeOffset>()), Times.Once); } }