Ejemplo n.º 1
0
        private static void ReadHeader(BinaryReader s)
        {
            uint num = StreamHelpers.ReadBigEndianUint32(s);

            if (num != 1920139830)
            {
                throw new InvalidDataException($"Got magic number {num:x} instead of expected {1920139830u:x}");
            }
        }
Ejemplo n.º 2
0
        private static void ReadHeader(BinaryReader s)
        {
            uint magic = StreamHelpers.ReadBigEndianUint32(s);

            if (magic != (uint)MagicNumber.Delta)
            {
                throw new InvalidDataException(string.Format("Got magic number {0:x} instead of expected {1:x}", magic, (uint)MagicNumber.Delta));
            }
        }
Ejemplo n.º 3
0
        public static SignatureFile ParseSignatureFile(Stream s)
        {
            var  result      = new SignatureFile();
            var  r           = new BinaryReader(s);
            uint magicNumber = StreamHelpers.ReadBigEndianUint32(r);

            if (magicNumber == (uint)MagicNumber.Blake2Signature)
            {
                result.StrongSumMethod = CalculateBlake2StrongSum;
            }
            else
            {
                throw new InvalidDataException(string.Format("Unknown magic number {0}", magicNumber));
            }

            result.BlockLength     = (int)StreamHelpers.ReadBigEndianUint32(r);
            result.StrongSumLength = (int)StreamHelpers.ReadBigEndianUint32(r);

            var   signatures = new List <BlockSignature>();
            ulong i          = 0;

            while (true)
            {
                byte[] weakSumBytes = r.ReadBytes(4);
                if (weakSumBytes.Length == 0)
                {
                    // we're at the end of the file
                    break;
                }

                int    weakSum   = (int)StreamHelpers.ConvertFromBigEndian(weakSumBytes);
                byte[] strongSum = r.ReadBytes(result.StrongSumLength);
                signatures.Add(new BlockSignature
                {
                    StartPos  = (ulong)result.BlockLength * i,
                    WeakSum   = weakSum,
                    StrongSum = strongSum
                });

                i++;
            }

            result.BlockLookup = signatures.ToLookup(sig => sig.WeakSum);
            return(result);
        }
Ejemplo n.º 4
0
        public static SignatureFile ParseSignatureFile(Stream s)
        {
            SignatureFile signatureFile = default(SignatureFile);
            BinaryReader  binaryReader  = new BinaryReader(s);
            uint          num           = StreamHelpers.ReadBigEndianUint32(binaryReader);

            if (num != 1920139575)
            {
                throw new InvalidDataException($"Unknown magic number {num}");
            }
            signatureFile.StrongSumMethod = CalculateBlake2StrongSum;
            signatureFile.BlockLength     = (int)StreamHelpers.ReadBigEndianUint32(binaryReader);
            signatureFile.StrongSumLength = (int)StreamHelpers.ReadBigEndianUint32(binaryReader);
            Dictionary <int, List <BlockSignature> > dictionary = new Dictionary <int, List <BlockSignature> >();
            ulong num2 = 0uL;

            while (true)
            {
                byte[] array = binaryReader.ReadBytes(4);
                if (array.Length == 0)
                {
                    break;
                }
                int    num3                 = (int)StreamHelpers.ConvertFromBigEndian(array);
                byte[] strongSum            = binaryReader.ReadBytes(signatureFile.StrongSumLength);
                List <BlockSignature> value = null;
                if (!dictionary.TryGetValue(num3, out value))
                {
                    value = new List <BlockSignature>();
                    dictionary.Add(num3, value);
                }
                value.Add(new BlockSignature
                {
                    StartPos  = (ulong)((long)signatureFile.BlockLength * (long)num2),
                    WeakSum   = num3,
                    StrongSum = strongSum
                });
                num2++;
            }
            signatureFile.BlockLookup = dictionary;
            return(signatureFile);
        }