This repository has been archived on 2023-04-04. You can view files and clone it, but cannot push or open issues or pull requests.
2020-03-13 15:20:02 +00:00
|
|
|
import * as core from "webcrypto-core";
|
|
|
|
import { CryptoKey as InternalCryptoKey } from "../keys";
|
|
|
|
|
|
|
|
const keyStorage = new WeakMap<core.CryptoKey, InternalCryptoKey>();
|
|
|
|
|
|
|
|
export function getCryptoKey(key: core.CryptoKey) {
|
|
|
|
const res = keyStorage.get(key);
|
|
|
|
if (!res) {
|
|
|
|
throw new core.OperationError("Cannot get CryptoKey from secure storage");
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setCryptoKey(value: InternalCryptoKey) {
|
2023-04-04 10:20:37 +00:00
|
|
|
const key = core.CryptoKey.create(
|
|
|
|
value.algorithm,
|
|
|
|
value.type,
|
|
|
|
value.extractable,
|
|
|
|
value.usages
|
|
|
|
);
|
2020-03-13 15:20:02 +00:00
|
|
|
Object.freeze(key);
|
|
|
|
|
|
|
|
keyStorage.set(key, value);
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|