public static byte[] decodeOnionUrl(String onionUrl) {
        if (!onionUrl.toLowerCase(Locale.ROOT).endsWith(".onion"))
            throw new IllegalArgumentException("not an onion URL: " + onionUrl);
        byte[] onionAddress = BASE32.decode(onionUrl.substring(0, onionUrl.length() - 6));
        if (onionAddress.length == 10) {
            // TORv2
            return onionAddress;
        } else if (onionAddress.length == 32 + 2 + 1) {
            // TORv3
            byte[] pubkey = Arrays.copyOfRange(onionAddress, 0, 32);
            byte[] checksum = Arrays.copyOfRange(onionAddress, 32, 34);
            byte torVersion = onionAddress[34];
            if (torVersion != 0x03)
                throw new IllegalArgumentException("unknown version: " + onionUrl);
            if (!Arrays.equals(checksum, onionChecksum(pubkey, torVersion)))
                throw new IllegalArgumentException("bad checksum: " + onionUrl);
            return pubkey;
        } else {
            throw new IllegalArgumentException("unrecognizable length: " + onionUrl);
        }
    }
@Test(expected = IllegalArgumentException.class)
    public void decodeOnionUrl_badLength() {
        TorUtils.decodeOnionUrl("aaa.onion");
    }