示例#1
0
        public void SHA1_ByteAmount()
        {
            var sha = SHA1Value.ComputeFileSHA1(ThisFile);

            sha.GetBytes().Count.Should().Be(20);
            sha.ToString().Length.Should().Be(40);
        }
示例#2
0
        public void SHA1_ToString_and_Parse()
        {
            var sha    = SHA1Value.ComputeFileSHA1(GetFilePath());
            var s      = sha.ToString();
            var shaBis = SHA1Value.Parse(s);

            shaBis.Should().Be(sha);
        }
示例#3
0
        public async Task SHA1_from_file_async()
        {
            var sha  = SHA1Value.ComputeFileSHA1(GetFilePath());
            var sha2 = await SHA1Value.ComputeFileSHA1Async(GetFilePath());

            sha2.Should().Be(sha);
            using (var compressedPath = new TemporaryFile())
            {
                using (var input = new FileStream(GetFilePath(), FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.SequentialScan | FileOptions.Asynchronous))
                    using (var compressed = new FileStream(compressedPath.Path, FileMode.Truncate, FileAccess.Write, FileShare.None, 4096, FileOptions.SequentialScan | FileOptions.Asynchronous))
                    {
                        var writer = GetCompressShellAsync(w => input.CopyToAsync(w));
                        await writer(compressed);
                    }
                var shaCompressed = await SHA1Value.ComputeFileSHA1Async(compressedPath.Path);

                shaCompressed.Should().NotBe(sha);
                var localSha = await SHA1Value.ComputeFileSHA1Async(compressedPath.Path, r => new GZipStream(r, CompressionMode.Decompress, true));

                localSha.Should().Be(sha);
            }
        }