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.
webcrypto/src/mechs/ec/helper.ts

33 lines
818 B
TypeScript
Raw Normal View History

2019-01-25 10:43:13 +00:00
import * as core from "webcrypto-core";
const namedOIDs: { [key: string]: string } = {
// P-256
"1.2.840.10045.3.1.7": "P-256",
"P-256": "1.2.840.10045.3.1.7",
// P-384
"1.3.132.0.34": "P-384",
"P-384": "1.3.132.0.34",
// P-521
"1.3.132.0.35": "P-521",
"P-521": "1.3.132.0.35",
// K-256
"1.3.132.0.10": "K-256",
"K-256": "1.3.132.0.10",
};
export function getNamedCurveByOid(oid: string) {
const namedCurve = namedOIDs[oid];
if (!namedCurve) {
throw new core.OperationError(`Cannot convert OID(${oid}) to WebCrypto named curve`);
}
return namedCurve;
}
export function getOidByNamedCurve(namedCurve: string) {
const oid = namedOIDs[namedCurve];
if (!oid) {
throw new core.OperationError(`Cannot convert WebCrypto named curve '${namedCurve}' to OID`);
}
return oid;
}