-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I have replaced using native "crypto" on using cross platform "crypto-js". I have added unit tests
- Loading branch information
mreal
committed
Aug 6, 2019
1 parent
fa84194
commit 77160b8
Showing
6 changed files
with
69 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
import test from 'ava'; | ||
import { MD5 } from './md5'; | ||
|
||
|
||
test('generate - return string', t => { | ||
t.is(MD5.createHex('test:test'), 'c4f961b4380ee24d982fed76ef36be9f'); | ||
}); |
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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
import * as crypto from 'crypto'; | ||
import cryptoMD5 from 'crypto-js/md5'; | ||
|
||
export class MD5 { | ||
public static createHex(raw: string): string { | ||
return crypto | ||
.createHash('md5') | ||
.update(raw) | ||
.digest('hex'); | ||
return cryptoMD5(raw).toString(); | ||
} | ||
} |
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,33 @@ | ||
import test from 'ava'; | ||
import { Nonce } from './nonce'; | ||
|
||
|
||
test('generate - return string', t => { | ||
t.is(typeof Nonce.generate(), 'string'); | ||
t.is(typeof Nonce.generate(10), 'string'); | ||
t.is(typeof Nonce.generate(1), 'string'); | ||
}); | ||
|
||
|
||
test('generate - default length equal 48', t => { | ||
t.is(Nonce.generate().length, 48); | ||
}); | ||
|
||
|
||
test('generate - custom length equal 20', t => { | ||
t.is(Nonce.generate(20).length, 20); | ||
}); | ||
|
||
test('generate - custom length equal 2', t => { | ||
t.is(Nonce.generate(2).length, 2); | ||
}); | ||
|
||
|
||
test('generate - custom length equal 1', t => { | ||
t.is(Nonce.generate(1).length, 1); | ||
}); | ||
|
||
test('generate - custom length lees then 1', t => { | ||
t.is(Nonce.generate(0).length, 0); | ||
t.is(Nonce.generate(-1).length, 0); | ||
}); |
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