-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding hooks and relevant tests, bbumping dependencies
- Loading branch information
Showing
51 changed files
with
1,897 additions
and
969 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* eslint linebreak-style: ["error", "windows"] */ | ||
/* eslint-disable no-use-before-define */ | ||
|
||
import React, { useState, useEffect } from 'react'; | ||
import hashString from '../JSHash.js'; | ||
import CONSTANTS from '../../Constants.js'; | ||
|
||
const useHash = ( | ||
hashAlgo = CONSTANTS.HashAlgorithms.md5, | ||
initialMessage = 'hello World', | ||
) => { | ||
const [Algo, setAlgo] = useState(hashAlgo); | ||
const [message, setMessage] = useState(initialMessage); | ||
const [hashed, setHashed] = useState(); | ||
useEffect(() => { | ||
const hash = () => hashString(message, Algo) | ||
.then((a) => setHashed(a)) | ||
.catch((er) => { | ||
console.error(er); | ||
}); | ||
hash(); | ||
}, [message, Algo]); | ||
|
||
return [hashed, setAlgo, setMessage]; | ||
}; | ||
|
||
export default useHash; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint linebreak-style: ["error", "windows"] */ | ||
/* eslint-disable no-use-before-define */ | ||
|
||
import React, { useState, useEffect } from 'react'; | ||
import hmacString from '../JSHmac.js'; | ||
import CONSTANTS from '../../Constants.js'; | ||
|
||
const useHmac = ( | ||
hmacAlgo = CONSTANTS.HmacAlgorithms.HmacMD5, | ||
initialMessage = 'hello World', | ||
initialSecret = 'SecretKey', | ||
) => { | ||
const [Algo, setAlgo] = useState(hmacAlgo); | ||
const [message, setMessage] = useState(initialMessage); | ||
const [secret, setSecret] = useState(initialSecret); | ||
const [hmaced, setHmaced] = useState(); | ||
useEffect(() => { | ||
const hmac = () => hmacString(message, secret, Algo) | ||
.then((a) => setHmaced(a)) | ||
.catch((er) => { | ||
console.error(er); | ||
}); | ||
hmac(); | ||
}, [message, secret, Algo]); | ||
|
||
return [hmaced, setAlgo, setMessage, setSecret]; | ||
}; | ||
|
||
export default useHmac; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* eslint linebreak-style: ["error", "windows"] */ | ||
/* eslint-disable no-restricted-syntax */ | ||
/* eslint-disable no-await-in-loop */ | ||
|
||
import CONSTANTS from '../Constants.js'; | ||
|
||
import { | ||
TestStrings, | ||
HmacMD5s, | ||
HmacSHA1s, | ||
HmacSHA224s, | ||
HmacSHA256s, | ||
HmacSHA384s, | ||
HmacSHA512s, | ||
} from './C.js'; | ||
import hmacString from '../JSHash/JSHmac.js'; | ||
|
||
describe('JSHash hasString Function', () => { | ||
test('HmacMD5', async () => { | ||
const iterator = TestStrings.entries(); | ||
for (const [index, value] of iterator) { | ||
await expect( | ||
hmacString(value, 'SecretKey', CONSTANTS.HmacAlgorithms.HmacMD5), | ||
).resolves.toEqual(HmacMD5s[index]); | ||
} | ||
}); | ||
|
||
test('HmacSHA1', async () => { | ||
const iterator = TestStrings.entries(); | ||
for (const [index, value] of iterator) { | ||
await expect( | ||
hmacString(value, 'SecretKey', CONSTANTS.HmacAlgorithms.HmacSHA1), | ||
).resolves.toEqual(HmacSHA1s[index]); | ||
} | ||
}); | ||
|
||
test('HmacSHA224', async () => { | ||
const iterator = TestStrings.entries(); | ||
for (const [index, value] of iterator) { | ||
await expect( | ||
hmacString(value, 'SecretKey', CONSTANTS.HmacAlgorithms.HmacSHA224), | ||
).resolves.toEqual(HmacSHA224s[index]); | ||
} | ||
}); | ||
|
||
test('HmacSHA256', async () => { | ||
const iterator = TestStrings.entries(); | ||
for (const [index, value] of iterator) { | ||
await expect( | ||
hmacString(value, 'SecretKey', CONSTANTS.HmacAlgorithms.HmacSHA256), | ||
).resolves.toEqual(HmacSHA256s[index]); | ||
} | ||
}); | ||
|
||
test('HmacSHA384', async () => { | ||
const iterator = TestStrings.entries(); | ||
for (const [index, value] of iterator) { | ||
await expect( | ||
hmacString(value, 'SecretKey', CONSTANTS.HmacAlgorithms.HmacSHA384), | ||
).resolves.toEqual(HmacSHA384s[index]); | ||
} | ||
}); | ||
|
||
test('HmacSHA512', async () => { | ||
const iterator = TestStrings.entries(); | ||
for (const [index, value] of iterator) { | ||
await expect( | ||
hmacString(value, 'SecretKey', CONSTANTS.HmacAlgorithms.HmacSHA512), | ||
).resolves.toEqual(HmacSHA512s[index]); | ||
} | ||
}); | ||
|
||
test('badHmac', async () => { | ||
await expect( | ||
hmacString('value', 'SecretKey', 'badHmacAlgo'), | ||
).rejects.toEqual(new Error('badHmacAlgo algorithm is not suported')); | ||
}); | ||
}); |
Oops, something went wrong.