Org.BouncyCastle.Pkix.PkixNameConstraintValidator.IsIPConstrained C# (CSharp) Méthode

IsIPConstrained() private méthode

private IsIPConstrained ( byte ip, byte constraint ) : bool
ip byte
constraint byte
Résultat bool
        private bool IsIPConstrained(byte[] ip, byte[] constraint)
        {
            int ipLength = ip.Length;

            if (ipLength != (constraint.Length / 2))
            {
                return false;
            }

            byte[] subnetMask = new byte[ipLength];
            Array.Copy(constraint, ipLength, subnetMask, 0, ipLength);

            byte[] permittedSubnetAddress = new byte[ipLength];

            byte[] ipSubnetAddress = new byte[ipLength];

            // the resulting IP address by applying the subnet mask
            for (int i = 0; i < ipLength; i++)
            {
                permittedSubnetAddress[i] = (byte)(constraint[i] & subnetMask[i]);
                ipSubnetAddress[i] = (byte)(ip[i] & subnetMask[i]);
            }

            return Org.BouncyCastle.Utilities.Arrays.AreEqual(permittedSubnetAddress, ipSubnetAddress);
        }