Пример #1
0
        public int CalculateHashCode(X500Name name)
        {
            int hashCodeValue = 0;

            Rdn[] rdns = name.GetRdns();

            // this needs to be order independent, like equals
            for (int i = 0; i != rdns.Length; i++)
            {
                if (rdns[i].IsMultiValued)
                {
                    AttributeTypeAndValue[] atv = rdns[i].GetTypesAndValues();

                    for (int j = 0; j != atv.Length; j++)
                    {
                        hashCodeValue ^= atv[j].Type.GetHashCode();
                        hashCodeValue ^= calcHashCode(atv[j].Value);
                    }
                }
                else
                {
                    hashCodeValue ^= rdns[i].First.Type.GetHashCode();
                    hashCodeValue ^= calcHashCode(rdns[i].First.Value);
                }
            }

            return(hashCodeValue);
        }
Пример #2
0
        public virtual bool AreEqual(X500Name name1, X500Name name2)
        {
            Rdn[] rdns1 = name1.GetRdns();
            Rdn[] rdns2 = name2.GetRdns();

            if (rdns1.Length != rdns2.Length)
            {
                return(false);
            }

            bool reverse = false;

            if (rdns1[0].First != null && rdns2[0].First != null)
            {
                reverse = !rdns1[0].First.Type.Equals(rdns2[0].First.Type); // guess forward
            }

            for (int i = 0; i != rdns1.Length; i++)
            {
                if (!foundMatch(reverse, rdns1[i], rdns2))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #3
0
        public override bool AreEqual(X500Name name1, X500Name name2)
        {
            Rdn[] rdns1 = name1.GetRdns();
            Rdn[] rdns2 = name2.GetRdns();

            if (rdns1.Length != rdns2.Length)
            {
                return(false);
            }

            for (int i = 0; i != rdns1.Length; i++)
            {
                if (!RdnAreEqual(rdns1[i], rdns2[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #4
0
        public override string ToString(X500Name name)
        {
            StringBuilder buf   = new StringBuilder();
            bool          first = true;

            Rdn[] rdns = name.GetRdns();

            for (int i = 0; i < rdns.Length; i++)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    buf.Append(',');
                }

                IetfUtils.AppendRdn(buf, rdns[i], mDefaultSymbols);
            }

            return(buf.ToString());
        }