Skip to content

Commit 94cd061

Browse files
committed
Reduce pbe digest dependencies.
- Custom builds should include digest algorithms they require. - Throw errors as needed if algorithms do not exist.
1 parent 4a046fc commit 94cd061

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/pbe.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var forge = require('./forge');
2121
require('./aes');
2222
require('./asn1');
2323
require('./des');
24-
require('./md.all');
24+
require('./md');
2525
require('./oids');
2626
require('./pbkdf2');
2727
require('./pem');
@@ -643,6 +643,9 @@ pki.pbe.generatePkcs12Key = function(password, salt, id, iter, n, md) {
643643
var j, l;
644644

645645
if(typeof md === 'undefined' || md === null) {
646+
if(!('sha1' in forge.md)) {
647+
throw new Error('"sha1" hash algorithm unavailable.');
648+
}
646649
md = forge.md.sha1.create();
647650
}
648651

@@ -929,6 +932,9 @@ pki.pbe.getCipherForPKCS12PBE = function(oid, params, password) {
929932
*/
930933
pki.pbe.opensslDeriveBytes = function(password, salt, dkLen, md) {
931934
if(typeof md === 'undefined' || md === null) {
935+
if(!('md5' in forge.md)) {
936+
throw new Error('"md5" hash algorithm unavailable.');
937+
}
932938
md = forge.md.md5.create();
933939
}
934940
if(salt === null) {
@@ -983,6 +989,9 @@ function prfAlgorithmToMessageDigest(prfAlgorithm) {
983989
'hmacWithSHA512'];
984990
throw error;
985991
}
992+
if(!factory || !(prfAlgorithm in factory)) {
993+
throw new Error('Unknown hash algorithm: ' + prfAlgorithm);
994+
}
986995
return factory[prfAlgorithm].create();
987996
}
988997

0 commit comments

Comments
 (0)