Created
May 31, 2019 13:27
-
-
Save WonderBeat/713bd4516f2074da5b0b6d1c16c02a5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.base.Preconditions; | |
interface TokenGenerator { | |
enum VerificationResult { OK, INVALID } | |
byte[] generate(); | |
VerificationResult verify(byte[] token); | |
} | |
public class CharTokenGenerator implements TokenGenerator { | |
private final String charset; | |
private final int length; | |
private final RNGenerator generator; | |
private final int checksum; | |
public CharTokenGenerator(String charset, int length, RNGenerator generator) { | |
this(charset, length, generator, 0); | |
} | |
public CharTokenGenerator(String charset, int length, RNGenerator generator, int checksum) { | |
Preconditions.checkArgument(charset.length() % 256 == 0); | |
Preconditions.checkArgument(length > 0); | |
Preconditions.checkArgument(checksum >= 0); | |
this.charset = charset; | |
this.length = length; | |
this.generator = generator; | |
this.checksum = checksum; | |
} | |
@Override | |
public byte[] generate() { | |
//... | |
} | |
@Override | |
public VerificationResult verify(byte[] token) { | |
//.. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment