ringfinger/js/types/Fingerprint.ts

49 lines
1021 B
TypeScript
Raw Normal View History

export default class Fingerprint
{
private static readonly CHARS_ALLOWED: string = '1234567890abcdef';
private readonly fingerprintId: number;
private readonly fingerprint: string;
private readonly userId: number;
public constructor(fingerprintId: number, fingerprint: string, userId: number)
{
if (!Fingerprint.validateFingerprint(fingerprint)) {
throw new Error(fingerprint + ' is not a valid fingerprint!');
}
this.fingerprintId = fingerprintId;
this.fingerprint = fingerprint;
this.userId = userId;
}
public getFingerprint(): string
{
return this.fingerprint;
}
public getUserId(): number
{
return this.userId;
}
public getFingerprintId(): number
{
return this.fingerprintId;
}
private static validateFingerprint(fingerprint: string): boolean
{
if (fingerprint.length !== 64) {
return false;
}
for (let i: number = 0; i < fingerprint.length; ++i) {
if (Fingerprint.CHARS_ALLOWED.indexOf(fingerprint[i]) === -1) {
return false;
}
}
return true;
}
}