Example #1
0
        public void Fabric()
        {
            var items         = Utilities.GetItemsStreamExample(SourceFiles);
            var payloadConfig = PayloadLayoutConfigurationFactory.CreateDefault(PayloadLayoutScheme.Fabric);

            DoMux(payloadConfig, items, SourceFiles);
        }
Example #2
0
        public void Frameshift()
        {
            var items         = Utilities.GetItemsBlockExample(SourceFiles);
            var payloadConfig = PayloadLayoutConfigurationFactory.CreateDefault(PayloadLayoutScheme.Frameshift);

            DoMux(payloadConfig, items, SourceFiles, true);
        }
Example #3
0
        public void Test()
        {
            var manifest = new Manifest
            {
                PayloadItems = new List <PayloadItem>(),

                PayloadOffset        = 69,
                PayloadConfiguration = PayloadLayoutConfigurationFactory.CreateDefault(PayloadLayoutSchemes.Frameshift)
            };

            manifest.PayloadItems.Add(new PayloadItem()
            {
                Encryption = SymmetricCipherConfigurationFactory.CreateBlockCipherConfiguration
                                 (SymmetricBlockCipher.AES, BlockCipherModes.CTR, BlockCipherPaddings.None)
            });

            var stream = StratCom.SerialiseDto(manifest);

            stream.Seek(0, SeekOrigin.Begin);
            var outputObj = StratCom.DeserialiseDTO <Manifest>(stream.ToArray());

            bool equal = manifest.Equals(outputObj);

            Assert.IsTrue(equal);
        }
Example #4
0
        public void Simple()
        {
            var inputObj = PayloadLayoutConfigurationFactory.CreateDefault(PayloadLayoutScheme.Simple);

            var stream = SerialiseToMemory(inputObj);

            stream.Seek(0, SeekOrigin.Begin);
            var outputObj = DeserialiseFromMemory <PayloadConfiguration>(stream);

            bool equal = inputObj.Equals(outputObj);

            Assert.IsTrue(equal);
        }
Example #5
0
        private static void SymmetricPackageTest(string testName, List <FileInfo> data, PayloadLayoutScheme scheme, bool outputToFile = false, bool precomputed = false)
        {
            // Process of writing destroys preKey variable passed in for security
            // We must copy it to a local variable before reading the package back
            var preKey = KeyProviders.Alice.SymmetricKeys.ElementAt(
                StratCom.EntropySupplier.Next(KeyProviders.Alice.SymmetricKeys.Count()));

            var totalLen = data.Sum(file => file.Length);
            int expLen   = (int)(totalLen * 1.1);

            TimeSpan enc, dec;

            using (var ms = new MemoryStream(expLen)) {
                var sw            = Stopwatch.StartNew();
                var packageWriter = new PackageWriter(preKey, lowEntropy: false, layoutScheme: scheme); // low entropy = false

                foreach (var file in data)
                {
                    packageWriter.AddFile(file.FullName);
                }

                if (precomputed)
                {
                    if (scheme == PayloadLayoutScheme.Simple)
                    {
                        packageWriter.SetPayloadConfiguration(PayloadLayoutConfigurationFactory.CreateSimplePreallocated(data.Count));
                    }
                    else if (scheme == PayloadLayoutScheme.Frameshift)
                    {
                        packageWriter.SetPayloadConfiguration(
                            PayloadLayoutConfigurationFactory.CreateFrameshiftPrecomputedVariable(data.Count));
                    }
                    else
                    {
                        throw new InvalidOperationException();
                    }
                }

                packageWriter.Write(ms, false);
                sw.Stop();
                enc = sw.Elapsed;
                sw.Reset();
                ms.Seek(0, SeekOrigin.Begin);
                if (outputToFile)
                {
                    using (var fs = new FileStream(
                               IOTestBase.PackageDestinationDirectory.FullName + Path.DirectorySeparatorChar + testName +
                               IOTestBase.PackageExtension, FileMode.Create)) {
                        ms.CopyTo(fs);
                    }
                    ms.Seek(0, SeekOrigin.Begin);
                }
                sw.Start();
                // Now read it back
                var readingPackage = PackageReader.FromStream(ms, KeyProviders.Alice);
                readingPackage.ReadToDirectory(IOTestBase.PackageDestinationDirectory.FullName, true);
                sw.Stop();
                dec = sw.Elapsed;
            }

            var megabytes = (double)totalLen / 1024 / 1024;

            Assert.Pass("{0} ms / {1:N2} MB/s -> {2} ms / {3:N2} MB/s.", enc.Milliseconds, (1000.0 / (double)enc.Milliseconds) * megabytes,
                        dec.Milliseconds, (1000.0 / (double)dec.Milliseconds) * megabytes);
        }