added checks
This commit is contained in:
parent
8e832eb380
commit
2c447c9381
1 changed files with 11 additions and 0 deletions
11
IGA.ts
11
IGA.ts
|
@ -102,6 +102,9 @@ function checksum(input: string) {
|
|||
}
|
||||
let bin = ""
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
if (input.charCodeAt(i) < 0 || input.charCodeAt(i) > 50000) {
|
||||
throw new Error("Character at index " + i + " is not a valid character")
|
||||
}
|
||||
bin += dec2bin(input.charCodeAt(i))
|
||||
}
|
||||
while (bin.length > 0) {
|
||||
|
@ -124,6 +127,11 @@ function hash(input: string, salt: number = 0, iterations: number = 32, len: num
|
|||
if (len < 16) {
|
||||
throw new Error("Length must be at least 16")
|
||||
}
|
||||
if (seed != undefined) {
|
||||
if (seed < 0 || seed > 65535) {
|
||||
throw new Error("Invalid seed")
|
||||
}
|
||||
}
|
||||
const padding = generatePadding(len, seed);
|
||||
let hash: number[] = []
|
||||
for (let i = 0; i < padding.padding.length; i++) {
|
||||
|
@ -131,6 +139,9 @@ function hash(input: string, salt: number = 0, iterations: number = 32, len: num
|
|||
}
|
||||
let plus = hash.length
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
if (input.charCodeAt(i) < 0 || input.charCodeAt(i) > 50000) {
|
||||
throw new Error("Character at index " + i + " is not a valid character")
|
||||
}
|
||||
hash[plus+i] = input.charCodeAt(i)
|
||||
}
|
||||
for (let i = 0; i < iterations; i++) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue