Example #1
0
        public static RollingSignature CreateRollingSignature(byte[] byteBlock, int length)
        {
            decimal s1 = 0;
            decimal s2 = 0;

            for (var i = 0; i < length; i++)
            {
                s1 += byteBlock[i];
            }

            for (int i = 0; i < length; i++)
            {
                s2 += (uint)(length - i) * byteBlock[i];
            }

            var signature = new RollingSignature() { Sig1 = s1, Sig2 = s2 };

            return signature;
        }
        // very manual writer... but want to see how small I can get the data.
        public static CompleteSignature ReadBinaryCompleteSignature(Stream s)
        {
            var sig = new CompleteSignature();

            var l = new List<BlockSignature>();

            var reader = new BinaryReader(s);

            int numberOfEntries = reader.ReadInt32();

            for (var i = 0; i < numberOfEntries; i++)
            {
                var entry = new BlockSignature();

                // 8 bytes. offset
                long offset = reader.ReadInt64();

                // 4 bytes. size
                int size = reader.ReadInt32();

                // 4 bytes. Block Number;
                int blockNumber = reader.ReadInt32();

                // 4 bytes. Rolling Signature.
                decimal sig1 = reader.ReadDecimal();
                decimal sig2 = reader.ReadDecimal();
                RollingSignature rollingSig = new RollingSignature() { Sig1 = sig1, Sig2 = sig2 };

                // should be 16 bytes.
                byte[] md5 = reader.ReadBytes(16);

                entry.BlockNumber = (UInt32)blockNumber;
                entry.RollingSig = (RollingSignature)rollingSig;
                entry.MD5Signature = md5;
                entry.Offset = offset;
                entry.Size = (uint)size;

                l.Add(entry);
            }
            sig.SignatureList = l.ToArray<BlockSignature>();
            return sig;
        }
Example #3
0
        internal static RollingSignature RollSignature(int length, byte previousByte, byte nextByte, RollingSignature existingSignature)
        {
            decimal s1 = 0;
            decimal s2 = 0;

            s1 = existingSignature.Sig1;
            s2 = existingSignature.Sig2;

            s1 = s1 - previousByte + nextByte;
            s2 = s2 - (previousByte * length) + s1;

            var res = new RollingSignature() { Sig1 = s1, Sig2 = s2 };
            return res;
        }