fmt
This commit is contained in:
@@ -10,4 +10,4 @@ export * as misc from './src/misc'
|
||||
export * as signature from './src/signature'
|
||||
export * as JWT from './src/jwt'
|
||||
|
||||
export {SecretBox,SecretWrap,PrivateBox,PrivateWrap,PwdBox,PwdWrap}
|
||||
export {SecretBox, SecretWrap, PrivateBox, PrivateWrap, PwdBox, PwdWrap}
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ export async function pbkdf(salt: Uint8Array, password: string): Promise<Uint8Ar
|
||||
return new Uint8Array(buffer)
|
||||
}
|
||||
export function ecdh(privkey: CryptoKey, pubkey: CryptoKey, usage: DHusage): Promise<CryptoKey> {
|
||||
log.trace("ecdh")
|
||||
log.trace('ecdh')
|
||||
const outputUsage: KeyUsage[] = usage === DHusage.box ? ['encrypt', 'decrypt'] : ['wrapKey', 'unwrapKey']
|
||||
return crypto.subtle.deriveKey(
|
||||
{
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ const log = logger('misc')
|
||||
|
||||
export enum Usage {
|
||||
sign,
|
||||
ecdh,
|
||||
ecdh
|
||||
}
|
||||
|
||||
export async function pubkey_toString(pubkey: CryptoKey): Promise<string> {
|
||||
@@ -29,8 +29,8 @@ export async function pubkey_fromString(pubkey_str: string, usage: Usage): Promi
|
||||
usage === Usage.ecdh ? [] : ['verify']
|
||||
)
|
||||
} catch (e) {
|
||||
log.warn("Failed to import public key")
|
||||
log.debug("Error :", e)
|
||||
log.warn('Failed to import public key')
|
||||
log.debug('Error :', e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -17,9 +17,9 @@ export default class PrivateBox {
|
||||
log.trace('Extractable :', extractable)
|
||||
try {
|
||||
return crypto.subtle.generateKey(consts.ECDH, extractable, ['deriveKey']) as Promise<CryptoKeyPair>
|
||||
} catch(e) {
|
||||
log.warn("Failed to generate a key")
|
||||
log.debug("Error :", e)
|
||||
} catch (e) {
|
||||
log.warn('Failed to generate a key')
|
||||
log.debug('Error :', e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ export default class PrivateBox {
|
||||
|
||||
const pubkey = await pubkey_fromString(parts[0], Usage.ecdh)
|
||||
if (pubkey === null) return null
|
||||
const box = SecretBox.fromString(parts.slice(1).join("."))
|
||||
const box = SecretBox.fromString(parts.slice(1).join('.'))
|
||||
if (box === null) return null
|
||||
|
||||
return new PrivateBox(pubkey, box)
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ export default class PrivateWrap {
|
||||
|
||||
const pubkey = await pubkey_fromString(parts[0], Usage.ecdh)
|
||||
if (pubkey === null) return null
|
||||
const box = SecretWrap.fromString(parts.slice(1).join("."))
|
||||
const box = SecretWrap.fromString(parts.slice(1).join('.'))
|
||||
if (box === null) return null
|
||||
|
||||
return new PrivateWrap(box, pubkey)
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ export default class PwdBox {
|
||||
|
||||
const salt = b642a(parts[0])
|
||||
if (salt === null) return null
|
||||
const box = SecretBox.fromString(parts.slice(1).join("."))
|
||||
const box = SecretBox.fromString(parts.slice(1).join('.'))
|
||||
if (box === null) return null
|
||||
|
||||
return new PwdBox(box, salt)
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ export default class PwdWrap {
|
||||
|
||||
const salt = b642a(parts[0])
|
||||
if (salt === null) return null
|
||||
const box = SecretWrap.fromString(parts.slice(1).join("."))
|
||||
const box = SecretWrap.fromString(parts.slice(1).join('.'))
|
||||
if (box === null) return null
|
||||
|
||||
return new PwdWrap(box, salt)
|
||||
|
||||
+4
-4
@@ -47,9 +47,9 @@ export default class SecretBox {
|
||||
this.cipher
|
||||
)
|
||||
return new Uint8Array(buffer)
|
||||
} catch(e) {
|
||||
log.warn("Failed to decrypt")
|
||||
log.debug("Error :", e)
|
||||
} catch (e) {
|
||||
log.warn('Failed to decrypt')
|
||||
log.debug('Error :', e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ export default class SecretBox {
|
||||
|
||||
const parts = data.split('.')
|
||||
if (parts.length < 2) {
|
||||
log.warn("Invalid parts count")
|
||||
log.warn('Invalid parts count')
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
+13
-5
@@ -46,10 +46,18 @@ export default class SecretWrap {
|
||||
public async decrypt(key: CryptoKey): Promise<CryptoKey | null> {
|
||||
log.trace('decrypt')
|
||||
try {
|
||||
return await crypto.subtle.unwrapKey(this.type, this.cipher, key, {name: consts.ENCRYPTION, iv: this.iv}, this.algorithm, true, this.usages)
|
||||
} catch(e) {
|
||||
log.warn("Failed to unwrap")
|
||||
log.debug("Error :", e)
|
||||
return await crypto.subtle.unwrapKey(
|
||||
this.type,
|
||||
this.cipher,
|
||||
key,
|
||||
{name: consts.ENCRYPTION, iv: this.iv},
|
||||
this.algorithm,
|
||||
true,
|
||||
this.usages
|
||||
)
|
||||
} catch (e) {
|
||||
log.warn('Failed to unwrap')
|
||||
log.debug('Error :', e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -62,7 +70,7 @@ export default class SecretWrap {
|
||||
algorithm: this.algorithm,
|
||||
usages: this.usages,
|
||||
type: this.type,
|
||||
iv,
|
||||
iv
|
||||
})
|
||||
}
|
||||
public static fromString(data: string): SecretWrap | null {
|
||||
|
||||
@@ -2,14 +2,14 @@ import {beforeAll, expect, test} from 'bun:test'
|
||||
import {PrivateBox} from '..'
|
||||
import {pubkey_toString} from '../src/misc'
|
||||
|
||||
let k1!: CryptoKeyPair;
|
||||
let k2!: CryptoKeyPair;
|
||||
let message!: Uint8Array;
|
||||
let k1!: CryptoKeyPair
|
||||
let k2!: CryptoKeyPair
|
||||
let message!: Uint8Array
|
||||
|
||||
beforeAll(async () => {
|
||||
k1 = await PrivateBox.gen(false)
|
||||
k2 = await PrivateBox.gen(true)
|
||||
message = new TextEncoder().encode("Salut ! ça va ?")
|
||||
message = new TextEncoder().encode('Salut ! ça va ?')
|
||||
})
|
||||
|
||||
test('base case', async () => {
|
||||
|
||||
@@ -2,9 +2,9 @@ import {beforeAll, expect, test} from 'bun:test'
|
||||
import {PrivateWrap, SecretBox} from '..'
|
||||
import {pubkey_toString} from '../src/misc'
|
||||
|
||||
let k1!: CryptoKeyPair;
|
||||
let k2!: CryptoKeyPair;
|
||||
let message!: CryptoKey;
|
||||
let k1!: CryptoKeyPair
|
||||
let k2!: CryptoKeyPair
|
||||
let message!: CryptoKey
|
||||
|
||||
beforeAll(async () => {
|
||||
k1 = await PrivateWrap.gen(false)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import {beforeAll, expect, test} from 'bun:test'
|
||||
import {PwdBox} from '..'
|
||||
|
||||
let k1!: string;
|
||||
let k2!: string;
|
||||
let message!: Uint8Array;
|
||||
let k1!: string
|
||||
let k2!: string
|
||||
let message!: Uint8Array
|
||||
|
||||
beforeAll(async () => {
|
||||
k1 = "abc"
|
||||
k2 = "def"
|
||||
message = new TextEncoder().encode("Salut ! ça va ?")
|
||||
k1 = 'abc'
|
||||
k2 = 'def'
|
||||
message = new TextEncoder().encode('Salut ! ça va ?')
|
||||
})
|
||||
|
||||
test('base case', async () => {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import {beforeAll, expect, test} from 'bun:test'
|
||||
import {PwdWrap, SecretBox} from '..'
|
||||
|
||||
let k1!: string;
|
||||
let k2!: string;
|
||||
let message!: CryptoKey;
|
||||
let k1!: string
|
||||
let k2!: string
|
||||
let message!: CryptoKey
|
||||
|
||||
beforeAll(async () => {
|
||||
k1 = "abc"
|
||||
k2 = "def"
|
||||
k1 = 'abc'
|
||||
k2 = 'def'
|
||||
message = await SecretBox.gen(true)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import {beforeAll, expect, test} from 'bun:test'
|
||||
import {SecretBox} from '..'
|
||||
|
||||
let k1!: CryptoKey;
|
||||
let k2!: CryptoKey;
|
||||
let message!: Uint8Array;
|
||||
let k1!: CryptoKey
|
||||
let k2!: CryptoKey
|
||||
let message!: Uint8Array
|
||||
|
||||
beforeAll(async () => {
|
||||
k1 = await SecretBox.gen(false)
|
||||
k2 = await SecretBox.gen(true)
|
||||
message = new TextEncoder().encode("Salut ! ça va ?")
|
||||
message = new TextEncoder().encode('Salut ! ça va ?')
|
||||
})
|
||||
|
||||
test('base case', async () => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {beforeAll, expect, test} from 'bun:test'
|
||||
import {SecretWrap} from '..'
|
||||
|
||||
let k1!: CryptoKey;
|
||||
let k2!: CryptoKey;
|
||||
let message!: CryptoKey;
|
||||
let k1!: CryptoKey
|
||||
let k2!: CryptoKey
|
||||
let message!: CryptoKey
|
||||
|
||||
beforeAll(async () => {
|
||||
k1 = await SecretWrap.gen(false)
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import {PrivateBox, PrivateWrap, SecretBox, SecretWrap, signature} from '..'
|
||||
import {beforeAll, expect, test} from 'bun:test'
|
||||
|
||||
let wrap_key!: CryptoKey;
|
||||
let wrap_key!: CryptoKey
|
||||
|
||||
beforeAll(async () => {
|
||||
wrap_key = await SecretWrap.gen(true)
|
||||
|
||||
Reference in New Issue
Block a user