예제 #1
0
        public async Task CryptoContainerTest()
        {
            using var fsContainer            = File.Create(containerPath);
            using ICryptoContainer container = IOBuilder.CreateContainer(key, fsContainer);
            await container.AddTextAsync(fileName, plainText, true);

            Student student = Student.Create();

            var readBack = await container.GetTextAsync(fileName);

            await container.AddAsync("student", student, true);

            var readStudent = await container.GetAsync <Student>("student");

            Assert.AreEqual(plainText, readBack);
            Assert.IsTrue(Student.AreEqual(student, readStudent));

            File.WriteAllText("input.txt", plainText);

            using FileStream fsFile = File.OpenRead("input.txt");

            await container.AddAsync("file", fsFile, true, null);

            using FileStream fs = File.Open("output.txt", FileMode.Create);

            await container.GetAsync("file", fs, null);

            fs.Close();

            Assert.AreEqual(plainText, File.ReadAllText("output.txt"));
        }
예제 #2
0
        public async Task ReadWriteTest()
        {
            using MemoryStream data = new MemoryStream(plainText.GetBytes <UTF8Encoding>());

            using var cryptoFile = IOBuilder.CreateFile(key);

            await cryptoFile.WriteAsync(data);

            using MemoryStream output = new MemoryStream();

            await cryptoFile.ReadAsync(output);

            Assert.AreEqual(data.ToArray().GetString <UTF8Encoding>(), output.ToArray().GetString <UTF8Encoding>());

            string outputString = await cryptoFile.ReadTextAsync();

            Assert.AreEqual(plainText, outputString);

            byte[] outputBytes = await cryptoFile.ReadBytesAsync();

            Assert.AreEqual(data.ToArray().GetString <UTF8Encoding>(), outputBytes.GetString <UTF8Encoding>());

            using MemoryStream outputStream = new MemoryStream();

            await cryptoFile.ReadAsync(outputStream);

            Assert.AreEqual(data.ToArray().GetString <UTF8Encoding>(), outputStream.ToArray().GetString <UTF8Encoding>());
        }
예제 #3
0
        public async Task DeserializeSerializeTest()
        {
            Student student = Student.Create();

            using var cryptoFile = IOBuilder.CreateFile(key);

            await cryptoFile.SerializeAsync(student);

            Student output = await cryptoFile.DeserializeAsync <Student>();

            Assert.AreEqual(student.Name, output.Name);
        }
예제 #4
0
        public async Task CryptoFileTest()
        {
            using var cryptoFile = File.Open(cipherName, FileMode.Create);

            using var alg = IOBuilder.CreateFile(key, cryptoFile);

            //Write to the cryptofile
            await alg.WriteTextAsync(plainText);

            var readOut = await alg.ReadTextAsync();

            Assert.AreEqual(plainText, readOut);
        }
예제 #5
0
        internal static RepositoryRow ReadFirst(
            IReadCondition <RepositoryRow> condition, string path)
        {
            RepositoryRow row = new RepositoryRow();

            using (BinaryReader reader = IOBuilder.CreateBinaryReader(path))
                while (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    Read(ref row, reader);
                    if (condition == null || condition.Matches(ref row))
                    {
                        return(row);
                    }
                }

            return(RepositoryRow.Empty);
        }
예제 #6
0
        internal static List <RepositoryRow> Read(
            IReadCondition <RepositoryRow> condition, string path)
        {
            List <RepositoryRow> result = new List <RepositoryRow>();
            RepositoryRow        row    = new RepositoryRow();

            using (BinaryReader reader = IOBuilder.CreateBinaryReader(path))
                while (reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    Read(ref row, reader);
                    if (condition == null || condition.Matches(ref row))
                    {
                        result.Add(row);
                    }
                }
            return(result);
        }