Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected static createTemplate(session: graphene.Session, alg: AesKeyGenParams, extractable: boolean, keyUsages: string[]): ITemplate {
const id = utils.GUID(session);
return {
token: !!process.env.WEBCRYPTO_PKCS11_TOKEN,
sensitive: !!process.env.WEBCRYPTO_PKCS11_SENSITIVE,
class: ObjectClass.SECRET_KEY,
keyType: KeyType.AES,
label: `AES-${alg.length}`,
id,
extractable,
derive: false,
sign: keyUsages.indexOf("sign") !== -1,
verify: keyUsages.indexOf("verify") !== -1,
encrypt: keyUsages.indexOf("encrypt") !== -1 || keyUsages.indexOf("wrapKey") !== -1,
decrypt: keyUsages.indexOf("decrypt") !== -1 || keyUsages.indexOf("unwrapKey") !== -1,
wrap: keyUsages.indexOf("wrapKey") !== -1,
unwrap: keyUsages.indexOf("unwrapKey") !== -1,
};
}
constructor(key: Key, alg: T) {
super();
this.p11Object = key;
switch (key.class) {
case ObjectClass.PUBLIC_KEY:
this.initPublicKey(key.toType());
break;
case ObjectClass.PRIVATE_KEY:
this.initPrivateKey(key.toType());
break;
case ObjectClass.SECRET_KEY:
this.initSecretKey(key.toType());
break;
default:
throw new core.CryptoError(`Wrong incoming session object '${ObjectClass[key.class]}'`);
}
this.algorithm = alg;
this.id = CryptoKey.getID(key);
this.onAssign();
}
export function create_template(session: Session, alg: AesKeyGenParams, extractable: boolean, keyUsages: string[]): ITemplate {
const id = utils.GUID(session);
return {
token: !!process.env.WEBCRYPTO_PKCS11_TOKEN,
sensitive: !!process.env.WEBCRYPTO_PKCS11_SENSITIVE,
class: ObjectClass.SECRET_KEY,
keyType: KeyType.AES,
label: `AES-${alg.length}`,
id,
extractable,
derive: false,
sign: keyUsages.indexOf("sign") !== -1,
verify: keyUsages.indexOf("verify") !== -1,
encrypt: keyUsages.indexOf("encrypt") !== -1,
decrypt: keyUsages.indexOf("decrypt") !== -1,
wrap: keyUsages.indexOf("wrapKey") !== -1,
unwrap: keyUsages.indexOf("unwrapKey") !== -1,
};
}