mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 05:52:52 +00:00
Refactor Yandex support a bit and fix some style issues
This commit is contained in:
parent
76c89f0fcc
commit
3d13117752
13 changed files with 199 additions and 192 deletions
|
@ -2,9 +2,9 @@ package com.beemdevelopment.aegis.crypto.otp;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.beemdevelopment.aegis.crypto.CryptoUtils;
|
||||
import com.beemdevelopment.aegis.encoding.Base32;
|
||||
import com.beemdevelopment.aegis.encoding.EncodingException;
|
||||
import com.beemdevelopment.aegis.otp.OtpInfoException;
|
||||
import com.beemdevelopment.aegis.otp.YandexInfo;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -23,11 +23,13 @@ public class YAOTPTest {
|
|||
};
|
||||
|
||||
@Test
|
||||
public void validateYaOtp() throws InvalidKeyException, NoSuchAlgorithmException, IOException {
|
||||
public void validateYaOtp()
|
||||
throws InvalidKeyException, NoSuchAlgorithmException, IOException, OtpInfoException {
|
||||
for (Vector testCase : TEST_CASES) {
|
||||
byte[] secret = YandexInfo.parseSecret(Base32.decode(testCase.secret));
|
||||
YAOTP otp = YAOTP.generateOTP(
|
||||
Base32.decode(testCase.secret.substring(0, 26)),
|
||||
CryptoUtils.toBytes(testCase.pin.toCharArray()),
|
||||
secret,
|
||||
testCase.pin,
|
||||
8,
|
||||
"HmacSHA256",
|
||||
testCase.timestamp,
|
||||
|
|
|
@ -5,6 +5,7 @@ import static org.junit.Assert.assertThrows;
|
|||
import com.beemdevelopment.aegis.encoding.Base32;
|
||||
import com.beemdevelopment.aegis.encoding.EncodingException;
|
||||
import com.beemdevelopment.aegis.otp.OtpInfoException;
|
||||
import com.beemdevelopment.aegis.otp.YandexInfo;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -19,14 +20,14 @@ public class YandexUtilsTest {
|
|||
|
||||
@Test(expected = Test.None.class)
|
||||
public void testValidationOk() throws EncodingException, OtpInfoException {
|
||||
YandexUtils.validateSecret(getBase32Vector(0));
|
||||
YandexUtils.validateSecret(getBase32Vector(1));
|
||||
YandexInfo.validateSecret(getBase32Vector(0));
|
||||
YandexInfo.validateSecret(getBase32Vector(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testYandexSecretValidation() {
|
||||
assertThrows(OtpInfoException.class, () -> YandexUtils.validateSecret(getBase32Vector(2)));
|
||||
assertThrows(OtpInfoException.class, () -> YandexUtils.validateSecret(getBase32Vector(3)));
|
||||
assertThrows(OtpInfoException.class, () -> YandexInfo.validateSecret(getBase32Vector(2)));
|
||||
assertThrows(OtpInfoException.class, () -> YandexInfo.validateSecret(getBase32Vector(3)));
|
||||
}
|
||||
|
||||
private byte[] getBase32Vector(int vectorIndex) throws EncodingException {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue