private long mLastCode;
private Token(Uri uri) throws TokenUriInvalidException {
- if (!uri.getScheme().equals("otpauth"))
+ String scheme = uri.getScheme();
+ String authority = uri.getAuthority();
+ String path = uri.getPath();
+
+ if (scheme == null || authority == null || path == null)
+ throw new TokenUriInvalidException();
+
+ if (!scheme.equals("otpauth"))
throw new TokenUriInvalidException();
- if (uri.getAuthority().equals("totp"))
+ if (authority.equals("totp"))
mType = TokenType.TOTP;
- else if (uri.getAuthority().equals("hotp"))
+ else if (authority.equals("hotp"))
mType = TokenType.HOTP;
else
throw new TokenUriInvalidException();
- String path = uri.getPath();
- if (path == null)
- throw new TokenUriInvalidException();
-
// Strip the path of its leading '/'
for (int i = 0; path.charAt(i) == '/'; i++)
path = path.substring(1);