-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ecdsa-p384-sha384 signatures
- Loading branch information
Showing
5 changed files
with
64 additions
and
85 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
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,40 @@ | ||
import { generateKeyPair, sign, verify } from 'crypto'; | ||
import { promisify } from 'util'; | ||
import { createSigner, createVerifier } from '../../src'; | ||
import { expect } from 'chai'; | ||
|
||
describe('ecdsa-p384-sha384', () => { | ||
describe('internal tests', () => { | ||
let ecdsaKeyPair: { publicKey: string, privateKey: string }; | ||
before('generate key pair', async () => { | ||
ecdsaKeyPair = await promisify(generateKeyPair)('ec', { | ||
namedCurve: 'P-384', | ||
publicKeyEncoding: { | ||
type: 'spki', | ||
format: 'pem', | ||
}, | ||
privateKeyEncoding: { | ||
type: 'pkcs8', | ||
format: 'pem', | ||
}, | ||
}); | ||
}); | ||
describe('signing', () => { | ||
it('signs a payload', async () => { | ||
const signer = createSigner(ecdsaKeyPair.privateKey, 'ecdsa-p384-sha384'); | ||
const data = Buffer.from('some random data'); | ||
const sig = await signer.sign(data); | ||
expect(signer.alg).to.equal('ecdsa-p384-sha384'); | ||
expect(sig).to.satisfy((arg: Buffer) => verify('sha384', data, ecdsaKeyPair.publicKey, arg)); | ||
}); | ||
}); | ||
describe('verifying', () => { | ||
it('verifies a signature', async () => { | ||
const verifier = createVerifier(ecdsaKeyPair.publicKey, 'ecdsa-p384-sha384'); | ||
const data = Buffer.from('some random data'); | ||
const sig = sign('sha384', data, ecdsaKeyPair.privateKey); | ||
expect(sig).to.satisfy((arg: Buffer) => verifier(data, arg)); | ||
}); | ||
}); | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.