예제 #1
0
        public static RawHash CalculateStream <T>(Stream stream) where T : HashAlgorithm
        {
            if (stream == null)
            {
                return(RawHash.Zero());
            }

            byte[] hash;
            using (var hashAlgorithm = GetHashAlgorithm(typeof(T)))
                hash = hashAlgorithm.ComputeHash(stream);
            return(new RawHash(hash));
        }
예제 #2
0
        public static RawHash CalculateStream(Stream stream)
        {
            if (stream == null)
            {
                return(RawHash.Zero());
            }

            byte[] hash;
            // There is a bug in spooky hash that prevents some trailing data from being added to the hash. It can also result in reading beyond the speicifed buffer.
            // Until this is addressed in the engine, we will revert to using MD5
            // There is a Jira ticket to investigate this further: https://jira.unity3d.com/browse/ADDR-1193?jql=text%20~%20%22spooky%22
            using (var hashAlgorithm = GetHashAlgorithm(typeof(MD5)))
                hash = hashAlgorithm.ComputeHash(stream);
            return(new RawHash(hash));
        }
예제 #3
0
        /// <summary>
        /// Creates the hash for a set of objects.
        /// </summary>
        /// <typeparam name="T">The hash algorithm type.</typeparam>
        /// <param name="objects">The objects.</param>
        /// <returns>Returns the hash of the set of objects.</returns>
        public static RawHash Calculate <T>(params object[] objects) where T : HashAlgorithm
        {
            if (objects == null)
            {
                return(RawHash.Zero());
            }

            RawHash rawHash;

            using (var stream = new HashStream(GetHashAlgorithm(typeof(T))))
            {
                GetRawBytes(stream, objects);
                rawHash = stream.GetHash();
            }
            return(rawHash);
        }
예제 #4
0
        /// <summary>
        /// Creates the hash for a stream of data.
        /// </summary>
        /// <param name="stream">The stream of data.</param>
        /// <returns>Returns the hash of the stream.</returns>
        public static RawHash CalculateStream(Stream stream)
        {
            if (stream == null)
            {
                return(RawHash.Zero());
            }
            if (stream is HashStream hs)
            {
                return(hs.GetHash());
            }

            byte[] hash;
            using (var hashAlgorithm = GetHashAlgorithm())
                hash = hashAlgorithm.ComputeHash(stream);
            return(new RawHash(hash));
        }
예제 #5
0
        public static RawHash CalculateStream(Stream stream)
        {
            if (stream == null)
            {
                return(RawHash.Zero());
            }

            byte[] hash;
#if UNITY_2019_3_OR_NEWER
            using (var hashAlgorithm = GetHashAlgorithm(typeof(SpookyHash)))
#else
            using (var hashAlgorithm = GetHashAlgorithm(typeof(MD5)))
#endif
                hash = hashAlgorithm.ComputeHash(stream);
            return(new RawHash(hash));
        }
예제 #6
0
        public static RawHash Calculate <T>(params object[] objects) where T : HashAlgorithm
        {
            if (objects == null)
            {
                return(RawHash.Zero());
            }

            RawHash rawHash;

            using (var stream = new MemoryStream())
            {
                GetRawBytes(stream, objects);
                stream.Position = 0;
                rawHash         = CalculateStream <T>(stream);
            }
            return(rawHash);
        }