bigint-crypto-utils/test/prime.ts

38 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-10-03 17:57:08 +00:00
import * as bcu from '#pkg'
2020-04-21 00:41:32 +00:00
describe('Testing prime generation', function () {
2021-03-25 12:40:04 +00:00
const bitLengths = [
0,
8,
255,
256,
258,
512,
1024,
2048,
3072
]
this.timeout(120000)
for (const bitLength of bitLengths) {
describe(`prime(${bitLength})`, function () {
2020-04-21 00:41:32 +00:00
if (bitLength > 0) {
it(`should return a random ${bitLength}-bits probable prime`, async function () {
2022-10-03 17:57:08 +00:00
const prime = await bcu.prime(bitLength)
chai.expect(bcu.bitLength(prime)).to.equal(bitLength)
2020-04-21 00:41:32 +00:00
})
} else {
2021-03-25 12:40:04 +00:00
it('should throw error', function () {
2022-10-03 17:57:08 +00:00
chai.expect(() => bcu.prime(bitLength)).to.throw(RangeError) // eslint-disable-line
2020-04-21 00:41:32 +00:00
})
}
})
}
describe('Testing sync (NOT-RECOMMENDED) version: primeSync()', function () {
it('should return a random 1024-bits probable prime', function () {
2022-10-03 17:57:08 +00:00
const prime = bcu.primeSync(1024, 16)
chai.expect(bcu.bitLength(prime)).to.equal(1024)
chai.expect(() => bcu.primeSync(0)).to.throw(RangeError)
})
})
})