Пример #1
0
        /// <summary>
        /// Compare against another object. Acceptable object types are <see cref="OctetString"/> and
        /// <see cref="System.String"/>.
        /// </summary>
        /// <param name="obj">Object of type <see cref="OctetString"/> or <see cref="System.String"/> to compare against</param>
        /// <returns>true if object content is the same, false if different or if incompatible object type</returns>
        public bool Equals(OctetString obj)
        {
            byte[] d = null;

            OctetString o = obj as OctetString;

            d = o.GetData();

            // check for null value in comparison
            if (d == null || _data == null)
            {
                if (d == null && _data == null)
                {
                    return(true); // both values are null
                }
                return(false);    // one value is not null
            }
            if (d.Length != _data.Length)
            {
                return(false); // Objects have different length
            }
            for (int cnt = 0; cnt < d.Length; cnt++)
            {
                if (d[cnt] != _data[cnt])
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Compare against another object. Acceptable object types are <see cref="OctetString"/> and
        /// <see cref="System.String"/>.
        /// </summary>
        /// <param name="obj">Object of type <see cref="OctetString"/> or <see cref="System.String"/> to compare against</param>
        /// <returns>true if object content is the same, false if different or if incompatible object type</returns>
        public override bool Equals(object obj)
        {
            byte[] d = null;
            if (obj is OctetString)
            {
                OctetString o = obj as OctetString;
                d = o.GetData();
            }
            else if (obj is string)
            {
                d = System.Text.UTF8Encoding.UTF8.GetBytes((string)obj);
            }
            else
            {
                return(false); // Incompatible object type
            }
            // check for null value in comparison
            if (d == null || _data == null)
            {
                if (d == null && _data == null)
                {
                    return(true); // both values are null
                }

                return(false); // one value is not null
            }
            if (d.Length != _data.Length)
            {
                return(false); // Objects have different length
            }
            for (int cnt = 0; cnt < d.Length; cnt++)
            {
                if (d[cnt] != _data[cnt])
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #3
0
 /// <summary>Copy constructor.</summary>
 /// <param name="second">The object to copy</param>
 public IpAddress(OctetString second) : this(second.GetData())
 {
 }
Пример #4
0
 /// <summary>
 /// IComparable interface implementation. Compare class contents against another class.
 /// </summary>
 /// <param name="other">OctetString class to compare against.</param>
 /// <returns>-1 if class value is greater (longer or higher value), 1 if byte array is greater or 0 if the same</returns>
 public int CompareTo(OctetString other)
 {
     return(CompareTo(other.GetData()));
 }