X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Forg%2Ffedorahosted%2Ffreeotp%2FToken.java;fp=src%2Forg%2Ffedorahosted%2Ffreeotp%2FToken.java;h=43342b1b566f46303282e3cb6376738446b60615;hb=995d219e668d27056965b8904cda8c743190b203;hp=9acecb4e8a86b2b6c09fb211051db76c218efbf9;hpb=3cdb62a44a020f44c071244da65447f3318f6e01;p=~andy%2Ffreeotp diff --git a/src/org/fedorahosted/freeotp/Token.java b/src/org/fedorahosted/freeotp/Token.java index 9acecb4..43342b1 100644 --- a/src/org/fedorahosted/freeotp/Token.java +++ b/src/org/fedorahosted/freeotp/Token.java @@ -54,20 +54,23 @@ public class Token { 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);