Esempio n. 1
0
        private void JsonStoreLoad()
        {
            string persistenceKey = appEncryptionJson.Store(payload, PersistenceBytes);

            Option <JObject> decryptedPayload = appEncryptionJson.Load(persistenceKey, PersistenceBytes);

            if (decryptedPayload.IsSome)
            {
                Assert.Equal(payload, (JObject)decryptedPayload);
            }
            else
            {
                throw new XunitException("Json load did not return decrypted payload");
            }
        }
Esempio n. 2
0
        private void BytesStoreLoad()
        {
            string persistenceKey = appEncryptionBytes.Store(payload, PersistenceBytes);

            Option <byte[]> decryptedPayload = appEncryptionBytes.Load(persistenceKey, PersistenceBytes);

            if (decryptedPayload.IsSome)
            {
                Assert.Equal(payload, (byte[])decryptedPayload);
            }
            else
            {
                throw new XunitException("Byte load did not return decrypted payload");
            }
        }
Esempio n. 3
0
        private void RunLoadStoreTest(int testIterations, string partitionId, int payloadSizeBytesBase)
        {
            try
            {
                using (AppEncryption <JObject, byte[]> partition =
                           appEncryptionSessionFactory.GetAppEncryptionJson(partitionId))
                {
                    string partitionPart = "partition-" + partitionId + "-";

                    for (int i = 0; i < testIterations; i++)
                    {
                        // Note the size will be slightly larger since we're adding extra unique meta
                        JObject jsonObject = PayloadGenerator.CreateRandomJsonPayload(payloadSizeBytesBase);
                        string  keyPart    = $"iteration-{i}";
                        jsonObject.Add("payload", partitionPart + keyPart);

                        string           persistenceKey       = partition.Store(jsonObject, PersistenceBytes);
                        Option <JObject> decryptedJsonPayload = partition.Load(persistenceKey, PersistenceBytes);
                        if (decryptedJsonPayload.IsSome)
                        {
                            JObject decryptedJson = (JObject)decryptedJsonPayload;
                            Assert.Equal(partitionPart + keyPart, decryptedJson.GetValue("payload").ToObject <string>());
                        }
                        else
                        {
                            throw new XunitException("Json load did not return decrypted payload");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e, "unexpected error during call");
                throw;
            }
        }