Exemplo n.º 1
0
        public bool Equals(IHeaders <TKey, TValue> h2, IHashingStrategy <TValue> valueHashingStrategy)
        {
            if (h2.Size != this.size)
            {
                return(false);
            }

            if (ReferenceEquals(this, h2))
            {
                return(true);
            }

            foreach (TKey name in this.Names())
            {
                IList <TValue> otherValues = h2.GetAll(name);
                IList <TValue> values      = this.GetAll(name);
                if (otherValues.Count != values.Count)
                {
                    return(false);
                }
                for (int i = 0; i < otherValues.Count; i++)
                {
                    if (!valueHashingStrategy.Equals(otherValues[i], values[i]))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public DefaultHeaders(IHashingStrategy <TKey> nameHashingStrategy,
                              IValueConverter <TValue> valueConverter, INameValidator <TKey> nameValidator, int arraySizeHint)
        {
            if (nameHashingStrategy is null)
            {
                CThrowHelper.ThrowArgumentNullException(CExceptionArgument.nameHashingStrategy);
            }
            if (valueConverter is null)
            {
                CThrowHelper.ThrowArgumentNullException(CExceptionArgument.valueConverter);
            }
            if (nameValidator is null)
            {
                CThrowHelper.ThrowArgumentNullException(CExceptionArgument.nameValidator);
            }

            _hashingStrategy = nameHashingStrategy;
            ValueConverter   = valueConverter;
            _nameValidator   = nameValidator;

            // Enforce a bound of [2, 128] because hashMask is a byte. The max possible value of hashMask is one less
            // than the length of this array, and we want the mask to be > 0.
            _entries  = new HeaderEntry <TKey, TValue> [FindNextPositivePowerOfTwo(Math.Max(2, Math.Min(arraySizeHint, 128)))];
            _hashMask = (byte)(_entries.Length - 1);
            _head     = new HeaderEntry <TKey, TValue>();
        }
Exemplo n.º 3
0
        public DefaultHeaders(IHashingStrategy <TKey> nameHashingStrategy,
                              IValueConverter <TValue> valueConverter, INameValidator <TKey> nameValidator, int arraySizeHint)
        {
            if (ReferenceEquals(nameHashingStrategy, null))
            {
                ThrowArgumentNullException(nameof(nameHashingStrategy));
            }
            if (ReferenceEquals(valueConverter, null))
            {
                ThrowArgumentNullException(nameof(valueConverter));
            }
            if (ReferenceEquals(nameValidator, null))
            {
                ThrowArgumentNullException(nameof(nameValidator));
            }

            this.hashingStrategy = nameHashingStrategy;
            this.ValueConverter  = valueConverter;
            this.nameValidator   = nameValidator;

            // Enforce a bound of [2, 128] because hashMask is a byte. The max possible value of hashMask is one less
            // than the length of this array, and we want the mask to be > 0.
            this.entries  = new HeaderEntry <TKey, TValue> [FindNextPositivePowerOfTwo(Math.Max(2, Math.Min(arraySizeHint, 128)))];
            this.hashMask = (byte)(this.entries.Length - 1);
            this.head     = new HeaderEntry <TKey, TValue>();
        }
Exemplo n.º 4
0
 public HashedFile(string path, IHashingStrategy alg, IFileHelper fileHelper)
 {
     if (!fileHelper.Exists(path))
     {
         throw new ArgumentException("HashedFile: Invalid path");
     }
     byte[] bytes = fileHelper.ReadAllBytes(path);
     hash      = alg.GetHash(bytes);
     this.path = path;
 }
Exemplo n.º 5
0
 public static string Hash(String input, string salt, IHashingStrategy strategy = null)
 {
     if (strategy != null)
     {
         return(strategy.Hash(input, salt));
     }
     else
     {
         return(HashingStrategy.Hash(input, salt));
     }
 }
 public AuthenticationDomainModel(IOptions <AuthenticationSettings> settings,
                                  IHashingStrategy hashingStrategy,
                                  ITokenGenerator tokenGenerator,
                                  IUserRepository userRepository,
                                  IRefreshTokenRepository tokenRepository)
 {
     this._settings        = settings.Value;
     this._hashingStrategy = hashingStrategy;
     this._tokenGenerator  = tokenGenerator;
     this._userRepository  = userRepository;
     this._tokenRepository = tokenRepository;
 }
Exemplo n.º 7
0
            public ValueEnumerator(DefaultHeaders <TKey, TValue> headers, TKey name)
            {
                if (name == null)
                {
                    ThrowArgumentNullException(nameof(name));
                }

                this.hashingStrategy = headers.hashingStrategy;
                this.hash            = this.hashingStrategy.HashCode(name);
                this.name            = name;
                this.node            = this.head = headers.entries[headers.Index(this.hash)];
                this.current         = default(TValue);
            }
Exemplo n.º 8
0
            public ValueEnumerator(DefaultHeaders <TKey, TValue> headers, TKey name)
            {
                if (name is null)
                {
                    CThrowHelper.ThrowArgumentNullException(CExceptionArgument.name);
                }

                _hashingStrategy = headers._hashingStrategy;
                _hash            = _hashingStrategy.HashCode(name);
                _name            = name;
                _node            = _head = headers._entries[headers.Index(_hash)];
                _current         = default;
            }
Exemplo n.º 9
0
        public int HashCode(IHashingStrategy <TValue> valueHashingStrategy)
        {
            int result = HashCodeSeed;

            foreach (TKey name in this.Names())
            {
                result = 31 * result + this.hashingStrategy.HashCode(name);
                IList <TValue> values = this.GetAll(name);
                for (int i = 0; i < values.Count; ++i)
                {
                    result = 31 * result + valueHashingStrategy.HashCode(values[i]);
                }
            }
            return(result);
        }
Exemplo n.º 10
0
        public bool Contains(TKey name, TValue value, IHashingStrategy <TValue> valueHashingStrategy)
        {
            if (name == null)
            {
                ThrowArgumentNullException(nameof(name));
            }

            int h = this.hashingStrategy.HashCode(name);
            int i = this.Index(h);
            HeaderEntry <TKey, TValue> e = this.entries[i];

            while (e != null)
            {
                if (e.Hash == h && this.hashingStrategy.Equals(name, e.key) &&
                    valueHashingStrategy.Equals(value, e.value))
                {
                    return(true);
                }
                e = e.Next;
            }
            return(false);
        }
Exemplo n.º 11
0
        public bool Contains(TKey name, TValue value, IHashingStrategy <TValue> valueHashingStrategy)
        {
            if (name is null)
            {
                CThrowHelper.ThrowArgumentNullException(CExceptionArgument.name);
            }

            int h = _hashingStrategy.HashCode(name);
            int i = Index(h);
            HeaderEntry <TKey, TValue> e = _entries[i];

            while (e is object)
            {
                if (e.Hash == h && _hashingStrategy.Equals(name, e._key) &&
                    valueHashingStrategy.Equals(value, e._value))
                {
                    return(true);
                }
                e = e.Next;
            }
            return(false);
        }
Exemplo n.º 12
0
 public DefaultHeaders(IHashingStrategy <TKey> nameHashingStrategy, IValueConverter <TValue> valueConverter, INameValidator <TKey> nameValidator)
     : this(nameHashingStrategy, valueConverter, nameValidator, 16)
 {
 }
Exemplo n.º 13
0
 public HashedFileFactory(IHashingStrategy hash, IFileHelper fileHelper)
 {
     this.hash       = hash;
     this.fileHelper = fileHelper;
 }
Exemplo n.º 14
0
 public CombinedHttpHeadersImpl(IHashingStrategy <AsciiString> nameHashingStrategy,
                                IValueConverter <ICharSequence> valueConverter, INameValidator <ICharSequence> nameValidator)
     : base(nameHashingStrategy, valueConverter, nameValidator)
 {
 }