Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const sourceData = (alg as RsaOaepParams).label ? new Buffer((alg as RsaOaepParams).label as Uint8Array) : undefined;
switch ((keyAlg as any).hash.name.toUpperCase()) {
case "SHA-1":
params = new graphene.RsaOaepParams(MechanismEnum.SHA1, RsaMgf.MGF1_SHA1, sourceData);
break;
case "SHA-224":
params = new graphene.RsaOaepParams(MechanismEnum.SHA224, RsaMgf.MGF1_SHA224, sourceData);
break;
case "SHA-256":
params = new graphene.RsaOaepParams(MechanismEnum.SHA256, RsaMgf.MGF1_SHA256, sourceData);
break;
case "SHA-384":
params = new graphene.RsaOaepParams(MechanismEnum.SHA384, RsaMgf.MGF1_SHA384, sourceData);
break;
case "SHA-512":
params = new graphene.RsaOaepParams(MechanismEnum.SHA512, RsaMgf.MGF1_SHA512, sourceData);
break;
default:
throw new AlgorithmError(AlgorithmError.UNSUPPORTED_ALGORITHM, (keyAlg as any).hash.name);
}
const res = { name: "RSA_PKCS_OAEP", params };
return res;
}
protected wc2pk11(alg: RsaOaepParams, keyAlg: RsaHashedKeyAlgorithm): graphene.IAlgorithm {
let params: graphene.RsaOaepParams;
const sourceData = alg.label ? Buffer.from((alg as RsaOaepParams).label as Uint8Array) : undefined;
switch (keyAlg.hash.name.toUpperCase()) {
case "SHA-1":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA1, graphene.RsaMgf.MGF1_SHA1, sourceData);
break;
case "SHA-224":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA224, graphene.RsaMgf.MGF1_SHA224, sourceData);
break;
case "SHA-256":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA256, graphene.RsaMgf.MGF1_SHA256, sourceData);
break;
case "SHA-384":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA384, graphene.RsaMgf.MGF1_SHA384, sourceData);
break;
case "SHA-512":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA512, graphene.RsaMgf.MGF1_SHA512, sourceData);
break;
default:
throw new core.OperationError(`Cannot create PKCS11 mechanism from algorithm '${keyAlg.hash.name}'`);
}
const res = { name: "RSA_PKCS_OAEP", params };
return res;
}
var params = null;
switch (key.algorithm.hash.name.toUpperCase()) {
case "SHA-1":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA1, graphene_pk11_1.RsaMgf.MGF1_SHA1);
break;
case "SHA-224":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA224, graphene_pk11_1.RsaMgf.MGF1_SHA224);
break;
case "SHA-256":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA256, graphene_pk11_1.RsaMgf.MGF1_SHA256);
break;
case "SHA-384":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA384, graphene_pk11_1.RsaMgf.MGF1_SHA384);
break;
case "SHA-512":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA512, graphene_pk11_1.RsaMgf.MGF1_SHA512);
break;
default:
throw new error.AlgorithmError(error.ERROR_WRONG_ALGORITHM, key.algorithm.hash.name);
}
var res = { name: "RSA_PKCS_OAEP", params: params };
return res;
};
RsaOAEP.ALGORITHM_NAME = exports.ALG_NAME_RSA_OAEP;
protected wc2pk11(alg: RsaOaepParams, keyAlg: RsaHashedKeyAlgorithm): graphene.IAlgorithm {
let params: graphene.RsaOaepParams;
const sourceData = alg.label ? Buffer.from((alg as RsaOaepParams).label as Uint8Array) : undefined;
switch (keyAlg.hash.name.toUpperCase()) {
case "SHA-1":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA1, graphene.RsaMgf.MGF1_SHA1, sourceData);
break;
case "SHA-224":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA224, graphene.RsaMgf.MGF1_SHA224, sourceData);
break;
case "SHA-256":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA256, graphene.RsaMgf.MGF1_SHA256, sourceData);
break;
case "SHA-384":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA384, graphene.RsaMgf.MGF1_SHA384, sourceData);
break;
case "SHA-512":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA512, graphene.RsaMgf.MGF1_SHA512, sourceData);
break;
default:
throw new core.OperationError(`Cannot create PKCS11 mechanism from algorithm '${keyAlg.hash.name}'`);
}
const res = { name: "RSA_PKCS_OAEP", params };
return res;
}
protected static wc2pk11(alg: Algorithm, keyAlg: KeyAlgorithm): IAlgorithm {
let params: graphene.RsaOaepParams;
const sourceData = (alg as RsaOaepParams).label ? new Buffer((alg as RsaOaepParams).label as Uint8Array) : undefined;
switch ((keyAlg as any).hash.name.toUpperCase()) {
case "SHA-1":
params = new graphene.RsaOaepParams(MechanismEnum.SHA1, RsaMgf.MGF1_SHA1, sourceData);
break;
case "SHA-224":
params = new graphene.RsaOaepParams(MechanismEnum.SHA224, RsaMgf.MGF1_SHA224, sourceData);
break;
case "SHA-256":
params = new graphene.RsaOaepParams(MechanismEnum.SHA256, RsaMgf.MGF1_SHA256, sourceData);
break;
case "SHA-384":
params = new graphene.RsaOaepParams(MechanismEnum.SHA384, RsaMgf.MGF1_SHA384, sourceData);
break;
case "SHA-512":
params = new graphene.RsaOaepParams(MechanismEnum.SHA512, RsaMgf.MGF1_SHA512, sourceData);
break;
default:
throw new AlgorithmError(AlgorithmError.UNSUPPORTED_ALGORITHM, (keyAlg as any).hash.name);
}
const res = { name: "RSA_PKCS_OAEP", params };
return res;
}
protected wc2pk11(alg: RsaOaepParams, keyAlg: RsaHashedKeyAlgorithm): graphene.IAlgorithm {
let params: graphene.RsaOaepParams;
const sourceData = alg.label ? Buffer.from((alg as RsaOaepParams).label as Uint8Array) : undefined;
switch (keyAlg.hash.name.toUpperCase()) {
case "SHA-1":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA1, graphene.RsaMgf.MGF1_SHA1, sourceData);
break;
case "SHA-224":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA224, graphene.RsaMgf.MGF1_SHA224, sourceData);
break;
case "SHA-256":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA256, graphene.RsaMgf.MGF1_SHA256, sourceData);
break;
case "SHA-384":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA384, graphene.RsaMgf.MGF1_SHA384, sourceData);
break;
case "SHA-512":
params = new graphene.RsaOaepParams(graphene.MechanismEnum.SHA512, graphene.RsaMgf.MGF1_SHA512, sourceData);
break;
default:
throw new core.OperationError(`Cannot create PKCS11 mechanism from algorithm '${keyAlg.hash.name}'`);
}
const res = { name: "RSA_PKCS_OAEP", params };
return res;
}
RsaOAEP.wc2pk11 = function (alg, key) {
var params = null;
switch (key.algorithm.hash.name.toUpperCase()) {
case "SHA-1":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA1, graphene_pk11_1.RsaMgf.MGF1_SHA1);
break;
case "SHA-224":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA224, graphene_pk11_1.RsaMgf.MGF1_SHA224);
break;
case "SHA-256":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA256, graphene_pk11_1.RsaMgf.MGF1_SHA256);
break;
case "SHA-384":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA384, graphene_pk11_1.RsaMgf.MGF1_SHA384);
break;
case "SHA-512":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA512, graphene_pk11_1.RsaMgf.MGF1_SHA512);
break;
default:
throw new error.AlgorithmError(error.ERROR_WRONG_ALGORITHM, key.algorithm.hash.name);
}
var res = { name: "RSA_PKCS_OAEP", params: params };
return res;
};
RsaOAEP.wc2pk11 = function (alg, key) {
var params = null;
switch (key.algorithm.hash.name.toUpperCase()) {
case "SHA-1":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA1, graphene_pk11_1.RsaMgf.MGF1_SHA1);
break;
case "SHA-224":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA224, graphene_pk11_1.RsaMgf.MGF1_SHA224);
break;
case "SHA-256":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA256, graphene_pk11_1.RsaMgf.MGF1_SHA256);
break;
case "SHA-384":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA384, graphene_pk11_1.RsaMgf.MGF1_SHA384);
break;
case "SHA-512":
params = new graphene_pk11_1.RsaOaepParams(graphene_pk11_1.MechanismEnum.SHA512, graphene_pk11_1.RsaMgf.MGF1_SHA512);
break;
default:
throw new error.AlgorithmError(error.ERROR_WRONG_ALGORITHM, key.algorithm.hash.name);
}