Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
fix hmac generate length param assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
microshine committed Apr 18, 2020
1 parent f19ab55 commit 07cf987
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 128 deletions.
5 changes: 2 additions & 3 deletions lib/mechs/hmac/hmac.ts
Expand Up @@ -2,19 +2,18 @@ import * as native from "native";
import { Convert } from "pvtsutils";
import * as core from "webcrypto-core";
import { CryptoKeyStorage } from "../../keys";
import { ShaCrypto } from "../sha/crypto";
import { HmacCryptoKey } from "./key";

export class HmacProvider extends core.HmacProvider {

public async onGenerateKey(algorithm: HmacKeyGenParams, extractable: boolean, keyUsages: KeyUsage[]): Promise<CryptoKey> {
return new Promise((resolve, reject) => {
const length = algorithm.length || ShaCrypto.size(algorithm.hash as Algorithm);
const length = algorithm.length || this.getDefaultLength((algorithm.hash as Algorithm).name);
native.HmacKey.generate(length, (err, key) => {
if (err) {
reject(err);
} else {
const hmacKey = HmacCryptoKey.create(algorithm, "secret", extractable, keyUsages);
const hmacKey = HmacCryptoKey.create({...algorithm, length} as HmacKeyAlgorithm, "secret", extractable, keyUsages);
hmacKey.native = key;
resolve(CryptoKeyStorage.setItem(hmacKey));
}
Expand Down

0 comments on commit 07cf987

Please sign in to comment.