auth-server-helper/lib/Blacklist.ts
Timo Hocker a4892f6262
Some checks failed
continuous-integration/drone/push Build is failing
blacklist, gateway
2020-12-12 15:53:47 +01:00

43 lines
863 B
TypeScript

interface Signature {
hash: string;
iat: Date;
}
class Blacklist {
private _signatures: Signature[];
public constructor () {
this._signatures = [];
}
public clear_before (date: Date) {
for (let i = this._signatures.length - 1; i >= 0; i--) {
if (this._signatures[i].iat < date)
this._signatures.splice (i, 1);
}
}
public add_signature (hash: string) {
this._signatures.push ({ iat: (new Date), hash });
}
public remove_signature (hash:string) {
for (let i = this._signatures.length - 1; i >= 0; i--) {
if (this._signatures[i].hash === hash)
this._signatures.splice (i, 1);
}
}
public is_valid (hash: string) {
for (const sig of this._signatures) {
if (sig.hash === hash)
return false;
}
return true;
}
}
const bl = (new Blacklist);
export default bl;