本文整理汇总了Java中com.google.android.apps.authenticator.Base32String.DecodingException类的典型用法代码示例。如果您正苦于以下问题:Java DecodingException类的具体用法?Java DecodingException怎么用?Java DecodingException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DecodingException类属于com.google.android.apps.authenticator.Base32String包,在下文中一共展示了DecodingException类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateKeyAndUpdateStatus
import com.google.android.apps.authenticator.Base32String.DecodingException; //导入依赖的package包/类
private boolean validateKeyAndUpdateStatus(boolean submitting) {
String userEnteredKey = getEnteredKey();
try {
byte[] decoded = Base32String.decode(userEnteredKey);
if (decoded.length < MIN_KEY_BYTES) {
// If the user is trying to submit a key that's too short, then
// display a message saying it's too short.
mKeyEntryField.setError(submitting ? getString(R.string.enter_key_too_short) : null);
return false;
} else {
mKeyEntryField.setError(null);
return true;
}
} catch (DecodingException e) {
mKeyEntryField.setError(getString(R.string.enter_key_illegal_char));
return false;
}
}
示例2: testRegressionValuesFromRfc4648
import com.google.android.apps.authenticator.Base32String.DecodingException; //导入依赖的package包/类
public void testRegressionValuesFromRfc4648() throws DecodingException {
// check encoding
assertEquals(OUTPUT1, Base32String.encode(INPUT1));
assertEquals(OUTPUT2, Base32String.encode(INPUT2));
assertEquals(OUTPUT3, Base32String.encode(INPUT3));
assertEquals(OUTPUT4, Base32String.encode(INPUT4));
// check decoding
MoreAsserts.assertEquals(INPUT1, Base32String.decode(OUTPUT1));
MoreAsserts.assertEquals(INPUT2, Base32String.decode(OUTPUT2));
MoreAsserts.assertEquals(INPUT3, Base32String.decode(OUTPUT3));
MoreAsserts.assertEquals(INPUT4, Base32String.decode(OUTPUT4));
}
示例3: checkDecoding
import com.google.android.apps.authenticator.Base32String.DecodingException; //导入依赖的package包/类
private byte[] checkDecoding(String s) {
try {
return Base32String.decode(s);
} catch (DecodingException e) {
return null; // decoding failed.
}
}
示例4: getCheckCode
import com.google.android.apps.authenticator.Base32String.DecodingException; //导入依赖的package包/类
static String getCheckCode(String secret) throws GeneralSecurityException,
DecodingException {
final byte[] keyBytes = Base32String.decode(secret);
Mac mac = Mac.getInstance("HMACSHA1");
mac.init(new SecretKeySpec(keyBytes, ""));
PasscodeGenerator pcg = new PasscodeGenerator(mac);
return pcg.generateResponseCode(0L);
}
示例5: decodeKey
import com.google.android.apps.authenticator.Base32String.DecodingException; //导入依赖的package包/类
private static byte[] decodeKey(String secret) throws DecodingException {
return Base32String.decode(secret);
}
示例6: testAmbiguousDecoding
import com.google.android.apps.authenticator.Base32String.DecodingException; //导入依赖的package包/类
/**
* Base32String implementation is not the same as that of RFC 4648, it drops
* the last incomplete chunk and thus accepts encoded strings that should have
* been rejected; also this results in multiple encoded strings being decoded
* to the same byte array.
* This test will catch any changes made regarding this behavior.
*/
public void testAmbiguousDecoding() throws DecodingException {
byte[] b16 = Base32String.decode("7777777777777777"); // 16 7s.
byte[] b17 = Base32String.decode("77777777777777777"); // 17 7s.
MoreAsserts.assertEquals(b16, b17);
}