示例#1
0
 public static string xxHash(this byte[] data, bool nullOnIOError = false)
 {
     try
     {
         var hash = new xxHashConfig();
         hash.HashSizeInBits = 64;
         hash.Seed           = 0x42;
         using (var fs = new MemoryStream(data))
         {
             var config = new xxHashConfig();
             config.HashSizeInBits = 64;
             using (var f = new StatusFileStream(fs, $"Hashing memory stream"))
             {
                 var value = xxHashFactory.Instance.Create(config).ComputeHash(f);
                 return(value.AsBase64String());
             }
         }
     }
     catch (IOException ex)
     {
         if (nullOnIOError)
         {
             return(null);
         }
         throw ex;
     }
 }
示例#2
0
 public static string FileHash(this string file, bool nullOnIOError = false)
 {
     try
     {
         var hash = new xxHashConfig();
         hash.HashSizeInBits = 64;
         hash.Seed           = 0x42;
         using (var fs = File.OpenRead(file))
         {
             var config = new xxHashConfig();
             config.HashSizeInBits = 64;
             using (var f = new StatusFileStream(fs, $"Hashing {Path.GetFileName(file)}"))
             {
                 var value = xxHashFactory.Instance.Create(config).ComputeHash(f);
                 return(value.AsBase64String());
             }
         }
     }
     catch (IOException ex)
     {
         if (nullOnIOError)
         {
             return(null);
         }
         throw ex;
     }
 }
示例#3
0
        public static async Task <string> FileHashAsync(this string file, bool nullOnIOError = false)
        {
            try
            {
                var hash = new xxHashConfig();
                hash.HashSizeInBits = 64;
                hash.Seed           = 0x42;
                using (var fs = File.OpenRead(file))
                {
                    var config = new xxHashConfig();
                    config.HashSizeInBits = 64;
                    var value = await xxHashFactory.Instance.Create(config).ComputeHashAsync(fs);

                    return(value.AsBase64String());
                }
            }
            catch (IOException ex)
            {
                if (nullOnIOError)
                {
                    return(null);
                }
                throw ex;
            }
        }
        public void xxHashConfig_Defaults_HaventChanged()
        {
            var xxHashConfigInstance = new xxHashConfig();

            Assert.Equal(32, xxHashConfigInstance.HashSizeInBits);
            Assert.Equal(0UL, xxHashConfigInstance.Seed);
        }
 public static IxxXHash Create(xxHashTypes type, xxHashConfig config)
 {
     config.CheckNull(nameof(config));
     config = config.Clone();
     config.HashSizeInBits = (int)type;
     return(new xxHashFunction(config));
 }
示例#6
0
        public static async Task <Hash> xxHashAsync(this Stream stream)
        {
            var config = new xxHashConfig {
                HashSizeInBits = 64
            };

            await using var f = new StatusFileStream(stream, $"Hashing memory stream");
            var value = await xxHashFactory.Instance.Create(config).ComputeHashAsync(f);

            return(Hash.FromULong(BitConverter.ToUInt64(value.Hash)));
        }
示例#7
0
        public static string FileHash(this string file)
        {
            var hash = new xxHashConfig();

            hash.HashSizeInBits = 64;
            hash.Seed           = 0x42;
            using (var fs = File.OpenRead(file))
            {
                var config = new xxHashConfig();
                config.HashSizeInBits = 64;
                var value = xxHashFactory.Instance.Create(config).ComputeHash(fs);
                return(value.AsBase64String());
            }
        }
        public void xxHashConfig_Clone_Works()
        {
            var xxHashConfigInstance = new xxHashConfig()
            {
                HashSizeInBits = 64,
                Seed           = 1337UL,
            };

            var xxHashConfigClone = xxHashConfigInstance.Clone();

            Assert.IsType <xxHashConfig>(xxHashConfigClone);

            Assert.Equal(xxHashConfigInstance.HashSizeInBits, xxHashConfigClone.HashSizeInBits);
            Assert.Equal(xxHashConfigInstance.Seed, xxHashConfigClone.Seed);
        }
示例#9
0
        public static Hash xxHash(this Stream stream)
        {
            var hash = new xxHashConfig();

            hash.HashSizeInBits = 64;
            hash.Seed           = 0x42;
            var config = new xxHashConfig {
                HashSizeInBits = 64
            };

            using var f = new StatusFileStream(stream, $"Hashing memory stream");
            var value = xxHashFactory.Instance.Create(config).ComputeHash(f);

            return(Hash.FromULong(BitConverter.ToUInt64(value.Hash)));
        }
        public UInt64 HashByteArray(byte[] b)
        {
            xxHashConfig config = new xxHashConfig()
            {
                HashSizeInBits = 64
            };
            var fac = xxHashFactory.Instance.Create(config);

            //xxHash h = new xxHash(64);
            //byte[] x = h.ComputeHash(b);

            byte[] x = fac.ComputeHash(b).Hash;

            return(BitConverter.ToUInt64(x, 0));
        }
示例#11
0
        public void xxHashFactory_Create_Works()
        {
            var defaultXxHashConfig = new xxHashConfig();

            var xxHashFactoryInstance = xxHashFactory.Instance;
            var xxHash = xxHashFactoryInstance.Create();

            Assert.NotNull(xxHash);
            Assert.IsType <xxHash_Implementation>(xxHash);


            var resultingXxHashConfig = xxHash.Config;

            Assert.Equal(defaultXxHashConfig.HashSizeInBits, resultingXxHashConfig.HashSizeInBits);
            Assert.Equal(defaultXxHashConfig.Seed, resultingXxHashConfig.Seed);
        }
示例#12
0
 public static Hash FileHash(this AbsolutePath file, bool nullOnIoError = false)
 {
     try
     {
         using var fs = file.OpenRead();
         var config = new xxHashConfig {
             HashSizeInBits = 64
         };
         using var f = new StatusFileStream(fs, $"Hashing {(string)file.FileName}");
         return(new Hash(BitConverter.ToUInt64(xxHashFactory.Instance.Create(config).ComputeHash(f).Hash)));
     }
     catch (IOException)
     {
         if (nullOnIoError)
         {
             return(Hash.Empty);
         }
         throw;
     }
 }
        public UInt64 HashStringJaccard(String s, int iteration)
        {
            byte[]       input  = Encoding.ASCII.GetBytes(s);
            xxHashConfig config = new xxHashConfig()
            {
                HashSizeInBits = 64
            };
            var fac = xxHashFactory.Instance.Create(config);

            byte[] x = fac.ComputeHash(input).Hash;

            //xxHash h = new xxHash();
            //byte[] x = fac.ComputeHash(s);

            for (int i = 0; i < iteration; i++)
            {
                x = fac.ComputeHash(x).Hash;
            }
            return(BitConverter.ToUInt64(x, 0));
        }
        public byte[] HashString(String s, int iteration)
        {
            byte[]       input  = Encoding.ASCII.GetBytes(s);
            xxHashConfig config = new xxHashConfig()
            {
                HashSizeInBits = 64
            };
            var fac = xxHashFactory.Instance.Create(config);

            byte[] x = fac.ComputeHash(input).Hash;
            //xxHash h = new xxHash(64);
            //byte[] x = h.ComputeHash(s);

            //lav et loop der bliver ved med at hashe den.
            for (int i = 0; i < iteration; i++)
            {
                x = fac.ComputeHash(x).Hash;
            }
            return(x);
        }
示例#15
0
        public static async Task <Hash> FileHashAsync(this AbsolutePath file, bool nullOnIOError = false)
        {
            try
            {
                await using var fs = file.OpenRead();
                var config = new xxHashConfig {
                    HashSizeInBits = 64
                };
                var value = await xxHashFactory.Instance.Create(config).ComputeHashAsync(fs);

                return(new Hash(BitConverter.ToUInt64(value.Hash)));
            }
            catch (IOException)
            {
                if (nullOnIOError)
                {
                    return(Hash.Empty);
                }
                throw;
            }
        }
        public xxHasher()
        {
            xxHashConfig XxHashConfig = this.CreatexxHashConfig();

            this.hasher = xxHashFactory.Instance.Create(XxHashConfig);
        }