Skip to content

Commit db6954b

Browse files
committed
Fix style.
Fix indentation, only use ascii, and align code style.
1 parent afbf7d8 commit db6954b

File tree

2 files changed

+61
-61
lines changed

2 files changed

+61
-61
lines changed

lib/asn1.js

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,69 +1185,69 @@ asn1.validate = function(obj, v, capture, errors) {
11851185
if(obj.constructed === v.constructed ||
11861186
typeof(v.constructed) === 'undefined') {
11871187
rval = true;
1188-
// Replace existing inner loop with this code
1189-
if (v.value && forge.util.isArray(v.value)) {
1190-
var j = 0;
1191-
for (var i = 0; rval && i < v.value.length; ++i) {
1192-
var schemaItem = v.value[i];
1193-
rval = schemaItem.optional || false;
1194-
1195-
// current child in the object
1196-
var objChild = obj.value[j];
1197-
1198-
// if there is no child left to match
1199-
if (!objChild) {
1200-
// if optional, ok (rval already true), else fail below
1201-
if (!schemaItem.optional) {
1202-
rval = false;
1203-
if (errors) {
1204-
errors.push('[' + v.name + '] missing required element: expected tagClass "' +
1205-
schemaItem.tagClass + '", type "' + schemaItem.type + '"');
1206-
}
1207-
}
1208-
continue;
1209-
}
1188+
// Replace existing inner loop with this code
1189+
if(v.value && forge.util.isArray(v.value)) {
1190+
var j = 0;
1191+
for(var i = 0; rval && i < v.value.length; ++i) {
1192+
var schemaItem = v.value[i];
1193+
rval = schemaItem.optional || false;
1194+
1195+
// current child in the object
1196+
var objChild = obj.value[j];
1197+
1198+
// if there is no child left to match
1199+
if(!objChild) {
1200+
// if optional, ok (rval already true), else fail below
1201+
if(!schemaItem.optional) {
1202+
rval = false;
1203+
if(errors) {
1204+
errors.push('[' + v.name + '] missing required element: expected tagClass "' +
1205+
schemaItem.tagClass + '", type "' + schemaItem.type + '"');
1206+
}
1207+
}
1208+
continue;
1209+
}
12101210

1211-
// If schema explicitly specifies tagClass/type, do a quick structural check
1212-
// to avoid unnecessary recursion/side-effects when tags clearly don't match.
1213-
var schemaHasTag = (typeof schemaItem.tagClass !== 'undefined' &&
1214-
typeof schemaItem.type !== 'undefined');
1215-
1216-
if (schemaHasTag &&
1217-
(objChild.tagClass !== schemaItem.tagClass || objChild.type !== schemaItem.type)) {
1218-
// Tags do not match.
1219-
if (schemaItem.optional) {
1220-
// Skip this schema element (don't consume objChild; don't call recursive validate).
1221-
rval = true;
1222-
continue;
1223-
} else {
1224-
// Required schema item mismatched — fail.
1225-
rval = false;
1226-
if (errors) {
1227-
errors.push('[' + v.name + '] Tag mismatch: expected (' +
1228-
schemaItem.tagClass + ',' + schemaItem.type + ') got (' +
1229-
objChild.tagClass + ',' + objChild.type + ')');
1211+
// If schema explicitly specifies tagClass/type, do a quick structural check
1212+
// to avoid unnecessary recursion/side-effects when tags clearly don't match.
1213+
var schemaHasTag = (typeof schemaItem.tagClass !== 'undefined' &&
1214+
typeof schemaItem.type !== 'undefined');
1215+
1216+
if(schemaHasTag &&
1217+
(objChild.tagClass !== schemaItem.tagClass || objChild.type !== schemaItem.type)) {
1218+
// Tags do not match.
1219+
if(schemaItem.optional) {
1220+
// Skip this schema element (don't consume objChild; don't call recursive validate).
1221+
rval = true;
1222+
continue;
1223+
} else {
1224+
// Required schema item mismatched - fail.
1225+
rval = false;
1226+
if(errors) {
1227+
errors.push('[' + v.name + '] Tag mismatch: expected (' +
1228+
schemaItem.tagClass + ',' + schemaItem.type + ') got (' +
1229+
objChild.tagClass + ',' + objChild.type + ')');
1230+
}
1231+
break;
1232+
}
1233+
}
1234+
1235+
// Tags are compatible (or schema did not declare tags) - dive into recursive validate.
1236+
var childRval = asn1.validate(objChild, schemaItem, capture, errors);
1237+
if(childRval) {
1238+
++j; // consume this child
1239+
rval = true;
1240+
} else if(schemaItem.optional) {
1241+
// validation failed but element is optional => skip schema item (don't consume child)
1242+
rval = true;
1243+
} else {
1244+
// required item failed
1245+
rval = false;
1246+
// errors should already be populated by recursive call; keep failing
1247+
break;
1248+
}
12301249
}
1231-
break;
12321250
}
1233-
}
1234-
1235-
// Tags are compatible (or schema did not declare tags) — dive into recursive validate.
1236-
var childRval = asn1.validate(objChild, schemaItem, capture, errors);
1237-
if (childRval) {
1238-
++j; // consume this child
1239-
rval = true;
1240-
} else if (schemaItem.optional) {
1241-
// validation failed but element is optional => skip schema item (don't consume child)
1242-
rval = true;
1243-
} else {
1244-
// required item failed
1245-
rval = false;
1246-
// errors should already be populated by recursive call; keep failing
1247-
break;
1248-
}
1249-
}
1250-
}
12511251

12521252
if(rval && capture) {
12531253
if(v.capture) {

lib/pkcs12.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ p12.pkcs12FromAsn1 = function(obj, strict, password) {
474474
if(macValue.getBytes() !== capture.macDigest) {
475475
throw new Error('PKCS#12 MAC could not be verified. Invalid password?');
476476
}
477-
} else if (Array.isArray(obj.value) && obj.value.length > 2) {
477+
} else if(Array.isArray(obj.value) && obj.value.length > 2) {
478478
/* This is pfx data that should ahve mac and verify macDigest */
479479
throw new Error('Invalid PKCS#12. macData field present but MAC was not validated.');
480480
}

0 commit comments

Comments
 (0)