public static void validateSecret(byte[] secret) throws OtpInfoException {
        if (secret.length != SECRET_LENGTH && secret.length != SECRET_FULL_LENGTH) {
            throw new OtpInfoException(String.format("Invalid Yandex secret length: %d bytes", secret.length));
        }

        // Secrets originating from a QR code do not have a checksum, so we assume those are valid
        if (secret.length == SECRET_LENGTH) {
            return;
        }

        char originalChecksum = (char) ((secret[secret.length - 2] & 0x0F) << 8 | secret[secret.length - 1] & 0xff);

        char accum = 0;
        int accumBits = 0;

        int inputTotalBitsAvailable = secret.length * 8 - 12;
        int inputIndex = 0;
        int inputBitsAvailable = 8;

        while (inputTotalBitsAvailable > 0) {
            int requiredBits = 13 - accumBits;
            if (inputTotalBitsAvailable < requiredBits) {
                requiredBits = inputTotalBitsAvailable;
            }

            while (requiredBits > 0) {
                int curInput = (secret[inputIndex] & (1 << inputBitsAvailable) - 1) & 0xff;
                int bitsToRead = Math.min(requiredBits, inputBitsAvailable);

                curInput >>= inputBitsAvailable - bitsToRead;
                accum = (char) (accum << bitsToRead | curInput);

                inputTotalBitsAvailable -= bitsToRead;
                requiredBits -= bitsToRead;
                inputBitsAvailable -= bitsToRead;
                accumBits += bitsToRead;

                if (inputBitsAvailable == 0) {
                    inputIndex += 1;
                    inputBitsAvailable = 8;
                }
            }

            if (accumBits == 13) {
                accum ^= 0b1_1000_1111_0011;
            }
            accumBits = 16 - getNumberOfLeadingZeros(accum);
        }

        if (accum != originalChecksum) {
            throw new OtpInfoException("Yandex secret checksum invalid");
        }
    }
@Test(expected = Test.None.class)
    public void testYandexSecretValidationOk() throws EncodingException, OtpInfoException {
        YandexInfo.validateSecret(getBase32Vector(0));
        YandexInfo.validateSecret(getBase32Vector(1));
    }