public static Range cidr()

in src/main/software/amazon/event/ruler/CIDR.java [124:154]


    public static Range cidr(String cidr) throws IllegalArgumentException {

        String[] slashed = cidr.split("/");
        if (slashed.length != 2) {
            barf("Malformed CIDR, one '/' required");
        }
        int maskBits = -1;
        try {
            maskBits = Integer.parseInt(slashed[1]);
        } catch (NumberFormatException e) {
            barf("Malformed CIDR, mask bits must be an integer");
        }
        if (maskBits < 0) {
            barf("Malformed CIDR, mask bits must not be negative");
        }

        byte[] providedIp = ipToBytes(slashed[0]);
        if (providedIp.length == 4) {
            if (maskBits > 31) {
                barf("IPv4 mask bits must be < 32");
            }
        } else {
            if (maskBits > 127) {
                barf("IPv6 mask bits must be < 128");
            }
        }

        byte[] minBytes = computeBottomBytes(providedIp, maskBits);
        byte[] maxBytes = computeTopBytes(providedIp, maskBits);
        return new Range(toHexDigits(minBytes), false, toHexDigits(maxBytes), false, true);
    }