jdk/src/java.base/share/classes/sun/security/x509/IPAddressName.java
changeset 35283 c5082624b79f
parent 34687 d302ed125dc9
equal deleted inserted replaced
35282:cbcd2afb6070 35283:c5082624b79f
   195                 (name.substring(0, slashNdx)).getAddress();
   195                 (name.substring(0, slashNdx)).getAddress();
   196             System.arraycopy(base, 0, address, 0, 16);
   196             System.arraycopy(base, 0, address, 0, 16);
   197 
   197 
   198             // append a mask corresponding to the num of prefix bits specified
   198             // append a mask corresponding to the num of prefix bits specified
   199             int prefixLen = Integer.parseInt(name.substring(slashNdx+1));
   199             int prefixLen = Integer.parseInt(name.substring(slashNdx+1));
   200             if (prefixLen > 128)
   200             if (prefixLen < 0 || prefixLen > 128) {
   201                 throw new IOException("IPv6Address prefix is longer than 128");
   201                 throw new IOException("IPv6Address prefix length (" +
       
   202                         prefixLen + ") in out of valid range [0,128]");
       
   203             }
   202 
   204 
   203             // create new bit array initialized to zeros
   205             // create new bit array initialized to zeros
   204             BitArray bitArray = new BitArray(MASKSIZE * 8);
   206             BitArray bitArray = new BitArray(MASKSIZE * 8);
   205 
   207 
   206             // set all most significant bits up to prefix length
   208             // set all most significant bits up to prefix length
   315             return true;
   317             return true;
   316 
   318 
   317         if (!(obj instanceof IPAddressName))
   319         if (!(obj instanceof IPAddressName))
   318             return false;
   320             return false;
   319 
   321 
   320         byte[] other = ((IPAddressName)obj).getBytes();
   322         IPAddressName otherName = (IPAddressName)obj;
       
   323         byte[] other = otherName.address;
   321 
   324 
   322         if (other.length != address.length)
   325         if (other.length != address.length)
   323             return false;
   326             return false;
   324 
   327 
   325         if (address.length == 8 || address.length == 32) {
   328         if (address.length == 8 || address.length == 32) {
   326             // Two subnet addresses
   329             // Two subnet addresses
   327             // Mask each and compare masked values
   330             // Mask each and compare masked values
   328             int maskLen = address.length/2;
   331             int maskLen = address.length/2;
   329             byte[] maskedThis = new byte[maskLen];
       
   330             byte[] maskedOther = new byte[maskLen];
       
   331             for (int i=0; i < maskLen; i++) {
   332             for (int i=0; i < maskLen; i++) {
   332                 maskedThis[i] = (byte)(address[i] & address[i+maskLen]);
   333                 byte maskedThis = (byte)(address[i] & address[i+maskLen]);
   333                 maskedOther[i] = (byte)(other[i] & other[i+maskLen]);
   334                 byte maskedOther = (byte)(other[i] & other[i+maskLen]);
   334                 if (maskedThis[i] != maskedOther[i]) {
   335                 if (maskedThis != maskedOther) {
   335                     return false;
   336                     return false;
   336                 }
   337                 }
   337             }
   338             }
   338             // Now compare masks
   339             // Now compare masks
   339             for (int i=maskLen; i < address.length; i++)
   340             for (int i=maskLen; i < address.length; i++)
   398         else if (inputName.getType() != NAME_IP)
   399         else if (inputName.getType() != NAME_IP)
   399             constraintType = NAME_DIFF_TYPE;
   400             constraintType = NAME_DIFF_TYPE;
   400         else if (((IPAddressName)inputName).equals(this))
   401         else if (((IPAddressName)inputName).equals(this))
   401             constraintType = NAME_MATCH;
   402             constraintType = NAME_MATCH;
   402         else {
   403         else {
   403             byte[] otherAddress = ((IPAddressName)inputName).getBytes();
   404             IPAddressName otherName = (IPAddressName)inputName;
       
   405             byte[] otherAddress = otherName.address;
   404             if (otherAddress.length == 4 && address.length == 4)
   406             if (otherAddress.length == 4 && address.length == 4)
   405                 // Two host addresses
   407                 // Two host addresses
   406                 constraintType = NAME_SAME_TYPE;
   408                 constraintType = NAME_SAME_TYPE;
   407             else if ((otherAddress.length == 8 && address.length == 8) ||
   409             else if ((otherAddress.length == 8 && address.length == 8) ||
   408                      (otherAddress.length == 32 && address.length == 32)) {
   410                      (otherAddress.length == 32 && address.length == 32)) {