Пример #1
0
        private async Task Delta(
            TestCase tc,
            RollingHashAlgorithm rollingHash,
            StrongHashAlgorithm strongHash)
        {
            var output    = new MemoryStream();
            var signature = tc.Sig(rollingHash, strongHash);

            await new Rdiff().DeltaAsync(
                signature: new MemoryStream(signature),
                newFile: new MemoryStream(tc.Version2),
                delta: output,
                System.Threading.CancellationToken.None);

            var expected = tc.Delta;
            var actual   = output.ToArray();

            AssertHelpers.Equal(expected, actual);
        }
Пример #2
0
        public SignatureOptions(
            int blockLength      = _defaultBlockLength,
            int strongHashLength = _defaultStrongHashLength,
            RollingHashAlgorithm rollingHashAlgorithm = _defaultRollingHashAlgorithm,
            StrongHashAlgorithm strongHashAlgorithm   = _defaultStrongHashAlgorithm)
        {
            if (blockLength <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(BlockLength));
            }
            _blockLength = blockLength;

            if (strongHashLength <= 0 || strongHashLength > 32)
            {
                throw new ArgumentOutOfRangeException(nameof(StrongHashLength));
            }
            _strongHashLength = strongHashLength;

            switch (rollingHashAlgorithm)
            {
            case RollingHashAlgorithm.Adler:
            case RollingHashAlgorithm.RabinKarp:
                _rollingHashAlgorithm = rollingHashAlgorithm;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(rollingHashAlgorithm));
            }

            switch (strongHashAlgorithm)
            {
            case StrongHashAlgorithm.Md4:
            case StrongHashAlgorithm.Blake2b:
                _strongHashAlgorithm = strongHashAlgorithm;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(strongHashAlgorithm));
            }
        }
Пример #3
0
        private async Task Sig(
            TestCase tc,
            RollingHashAlgorithm rollingHash,
            StrongHashAlgorithm strongHash)
        {
            var output = new MemoryStream();

            await new Rdiff().SignatureAsync(
                oldFile: new MemoryStream(tc.Version1),
                signature: output,
                new SignatureOptions(
                    tc.BlockLength,
                    tc.StrongHashLength,
                    rollingHash,
                    strongHash),
                System.Threading.CancellationToken.None);

            var expected = tc.Sig(rollingHash, strongHash);
            var actual   = output.ToArray();

            AssertHelpers.Equal(expected, actual);
        }
Пример #4
0
 public byte[] Sig(
     RollingHashAlgorithm rollingHash,
     StrongHashAlgorithm strongHash) =>
 rollingHash switch
 {
Пример #5
0
 public Task Delta_LoremIpsum(
     RollingHashAlgorithm rollingHash,
     StrongHashAlgorithm strongHash) =>
 Delta(TestCase.LoremIpsum, rollingHash, strongHash);
Пример #6
0
 public Task Delta_Hello_Heollo_BlockLength_2(
     RollingHashAlgorithm rollingHash,
     StrongHashAlgorithm strongHash) =>
 Delta(TestCase.Hello_Heollo_BlockLength_2, rollingHash, strongHash);
Пример #7
0
 public Task Delta_Hello_Hellooo_StrongHashLength_16(
     RollingHashAlgorithm rollingHash,
     StrongHashAlgorithm strongHash) =>
 Delta(TestCase.Hello_Hellooo_StrongHashLength_16, rollingHash, strongHash);
Пример #8
0
 public Task Delta_Hello_Hellooo_Default(
     RollingHashAlgorithm rollingHash,
     StrongHashAlgorithm strongHash) =>
 Delta(TestCase.Hello_Hellooo_Default, rollingHash, strongHash);
Пример #9
0
 public Task Sig_LoremIpsum(
     RollingHashAlgorithm rollingHash,
     StrongHashAlgorithm strongHash) =>
 Sig(TestCase.LoremIpsum, rollingHash, strongHash);
Пример #10
0
 public Task Sig_Hello_StrongHashLength_17(
     RollingHashAlgorithm rollingHash,
     StrongHashAlgorithm strongHash) =>
 Sig(TestCase.Hello_Hellooo_StrongHashLength_17, rollingHash, strongHash);
Пример #11
0
 public Task Sig_Hello_BlockLength_2(
     RollingHashAlgorithm rollingHash,
     StrongHashAlgorithm strongHash) =>
 Sig(TestCase.Hello_Hellooo_BlockLength_2, rollingHash, strongHash);
Пример #12
0
 public Task Sig_Hello_Default(
     RollingHashAlgorithm rollingHash,
     StrongHashAlgorithm strongHash) =>
 Sig(TestCase.Hello_Hellooo_Default, rollingHash, strongHash);