From 2148dd814d1fc4c4b831e058b5e606f976f505a2 Mon Sep 17 00:00:00 2001 From: microshine Date: Thu, 28 Mar 2019 16:31:50 +0300 Subject: [PATCH] Remove length checking for HMCAC importKey --- src/mechs/hmac/hmac.ts | 10 ---------- test/hmac.ts | 25 ++++++++++++++++++------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/mechs/hmac/hmac.ts b/src/mechs/hmac/hmac.ts index 6c11e4b..6b86c86 100644 --- a/src/mechs/hmac/hmac.ts +++ b/src/mechs/hmac/hmac.ts @@ -58,16 +58,6 @@ export class HmacProvider extends core.HmacProvider { key.extractable = extractable; key.usages = keyUsages; - // check key length - switch (key.algorithm.length) { - case 128: - case 192: - case 256: - break; - default: - throw new core.OperationError("keyData: Is wrong key length"); - } - return key; } diff --git a/test/hmac.ts b/test/hmac.ts index 130293a..1e5d465 100644 --- a/test/hmac.ts +++ b/test/hmac.ts @@ -2,7 +2,7 @@ import { Convert } from "pvtsutils"; import { Crypto } from "../src"; import { ITestGenerateKeyAction, testCrypto } from "./helper"; -context("HMAC", () => { +context.only("HMAC", () => { const crypto = new Crypto(); @@ -69,7 +69,7 @@ context("HMAC", () => { }, ], import: [ - { + { // JWK SHA-1 name: "JWK SHA-1", format: "jwk", data: { @@ -87,7 +87,7 @@ context("HMAC", () => { extractable: true, keyUsages: ["sign", "verify"], }, - { + { // JWK SHA-256 name: "JWK SHA-256", format: "jwk", data: { @@ -104,7 +104,7 @@ context("HMAC", () => { extractable: true, keyUsages: ["sign", "verify"], }, - { + { // JWK SHA-384 name: "JWK SHA-384", format: "jwk", data: { @@ -121,7 +121,7 @@ context("HMAC", () => { extractable: true, keyUsages: ["sign", "verify"], }, - { + { // JWK SHA-512 name: "JWK SHA-512", format: "jwk", data: { @@ -138,8 +138,8 @@ context("HMAC", () => { extractable: true, keyUsages: ["sign", "verify"], }, - { - name: "raw", + { // raw 128 + name: "raw 128", format: "raw", data: Convert.FromBase64("AQIDBAUGBwgJAAECAwQFBg"), algorithm: { @@ -149,6 +149,17 @@ context("HMAC", () => { extractable: true, keyUsages: ["sign", "verify"], }, + { // raw 160 + name: "raw 160", + format: "raw", + data: new Uint8Array(20), + algorithm: { + name: "HMAC", + hash: "SHA-512", + } as HmacImportParams, + extractable: true, + keyUsages: ["sign", "verify"], + }, ], }, },