-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the function signature overloads of
SubtleCrypto#exportKey
mor…
…e flexible (#1593) Co-authored-by: saschanaz <[email protected]>
- Loading branch information
1 parent
9e884a8
commit 13115c8
Showing
6 changed files
with
54 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,46 @@ | ||
const usageInline = crypto.subtle.generateKey({ | ||
name: "AES-GCM", | ||
length: 256, | ||
}, true, ['encrypt', 'decrypt']) | ||
|
||
const usageConst = crypto.subtle.generateKey( { | ||
name: "AES-GCM", | ||
length: 256, | ||
}, true, ['encrypt', 'decrypt'] as const) | ||
|
||
const keyUsage: ReadonlyArray<KeyUsage> = ['encrypt', 'decrypt'] | ||
const usageAsReadonly = crypto.subtle.generateKey( { | ||
name: "AES-GCM", | ||
length: 256, | ||
}, true, keyUsage) | ||
function assertType<T>(_x: T) {} | ||
|
||
const mockKey = {} as CryptoKey; | ||
|
||
assertType<Promise<JsonWebKey>>(crypto.subtle.exportKey("jwk", mockKey)); | ||
assertType<Promise<ArrayBuffer>>(crypto.subtle.exportKey("pkcs8", mockKey)); | ||
assertType<Promise<ArrayBuffer>>(crypto.subtle.exportKey("raw", mockKey)); | ||
assertType<Promise<ArrayBuffer>>(crypto.subtle.exportKey("spki", mockKey)); | ||
|
||
assertType<Promise<ArrayBuffer | JsonWebKey>>( | ||
crypto.subtle | ||
.exportKey("" as KeyFormat, mockKey) | ||
.then((ambiguousExportedKeyData) => | ||
ambiguousExportedKeyData instanceof ArrayBuffer | ||
? (ambiguousExportedKeyData satisfies ArrayBuffer) | ||
: (ambiguousExportedKeyData satisfies JsonWebKey) | ||
) | ||
); | ||
|
||
const usageInline = crypto.subtle.generateKey( | ||
{ | ||
name: "AES-GCM", | ||
length: 256, | ||
}, | ||
true, | ||
["encrypt", "decrypt"] | ||
); | ||
|
||
const usageConst = crypto.subtle.generateKey( | ||
{ | ||
name: "AES-GCM", | ||
length: 256, | ||
}, | ||
true, | ||
["encrypt", "decrypt"] as const | ||
); | ||
|
||
const keyUsage: ReadonlyArray<KeyUsage> = ["encrypt", "decrypt"]; | ||
const usageAsReadonly = crypto.subtle.generateKey( | ||
{ | ||
name: "AES-GCM", | ||
length: 256, | ||
}, | ||
true, | ||
keyUsage | ||
); |