Implement strength for whole library
This commit is contained in:
+4
-1
@@ -1,5 +1,8 @@
|
||||
import {Console} from 'logger-console'
|
||||
import {writers, Level} from 'log'
|
||||
import {Level, writers, options} from 'log'
|
||||
import {set_strength, Strength} from '..'
|
||||
|
||||
options.verbose = false
|
||||
const logger = new Console({minLevel: Level.TRACE, with_color: true})
|
||||
writers.set('console', logger)
|
||||
set_strength(Strength.weak)
|
||||
|
||||
+9
-5
@@ -1,5 +1,6 @@
|
||||
import {describe, expect, test} from 'bun:test'
|
||||
import {kdf, PrivateWrap, SecretBox, SecretWrap} from '..'
|
||||
import {kdf, PrivateWrap, SecretBox, SecretWrap, set_strength, Strength} from '..'
|
||||
import {BYTE_LENGTH} from '../src/const'
|
||||
|
||||
async function test_keys(
|
||||
k1: CryptoKey,
|
||||
@@ -84,7 +85,7 @@ describe('HKDF', () => {
|
||||
await test_keys(k1!, k2!, usage1, true, false)
|
||||
})
|
||||
test('Minimum size', async () => {
|
||||
const k = await kdf.hkdf(new Uint8Array(31), usage1)
|
||||
const k = await kdf.hkdf(new Uint8Array(BYTE_LENGTH() - 1), usage1)
|
||||
expect(k).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -114,9 +115,12 @@ describe('PBKDF', () => {
|
||||
expect(k1).not.toEqual(k2)
|
||||
})
|
||||
test('Different strengths', async () => {
|
||||
const k1 = await kdf.pbkdf(salt1, pwd2, kdf.Strength.weak)
|
||||
const k2 = await kdf.pbkdf(salt1, pwd1, kdf.Strength.moderate)
|
||||
const k3 = await kdf.pbkdf(salt1, pwd2, kdf.Strength.strong)
|
||||
set_strength(Strength.weak)
|
||||
const k1 = await kdf.pbkdf(salt1, pwd2)
|
||||
set_strength(Strength.moderate)
|
||||
const k2 = await kdf.pbkdf(salt1, pwd1)
|
||||
set_strength(Strength.strong)
|
||||
const k3 = await kdf.pbkdf(salt1, pwd2)
|
||||
expect(k1).not.toEqual(k2)
|
||||
expect(k1).not.toEqual(k3)
|
||||
expect(k2).not.toEqual(k3)
|
||||
|
||||
+2
-1
@@ -39,11 +39,12 @@ test('Signature', async () => {
|
||||
const k = await signature.gen(false)
|
||||
const message = crypto.getRandomValues(new Uint8Array(8))
|
||||
const signed = await signature.sign(message, k.privateKey)
|
||||
expect(signed).not.toBeNull()
|
||||
|
||||
const ser = await pubkey_toString(k.publicKey)
|
||||
const de = await pubkey_fromString(ser, Usage.sign)
|
||||
expect(de).not.toBeNull()
|
||||
|
||||
const verification = await signature.verify(message, de!, signed)
|
||||
const verification = await signature.verify(message, de!, signed!)
|
||||
expect(verification).toBeTrue()
|
||||
})
|
||||
|
||||
+2
-1
@@ -26,7 +26,8 @@ test('Signature', async () => {
|
||||
|
||||
const message = new Uint8Array(8)
|
||||
const signed = await signature.sign(message, privk)
|
||||
const verification = await signature.verify(message, k.publicKey, signed)
|
||||
expect(signed).not.toBeNull()
|
||||
const verification = await signature.verify(message, k.publicKey, signed!)
|
||||
expect(verification).toBeTrue()
|
||||
})
|
||||
test('SecretWrap', async () => {
|
||||
|
||||
Reference in New Issue
Block a user