fmt
This commit is contained in:
+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 {
|
||||
|
||||
Reference in New Issue
Block a user