Skip to content

Commit

Permalink
Merge pull request #17 from thatsdone/hotfix/14
Browse files Browse the repository at this point in the history
[enh] add get_oid_value_all() to http/certs/js/x509 example.
  • Loading branch information
xeioex authored Jul 8, 2022
2 parents 1222ae9 + 4a83234 commit 4935efc
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion njs/http/certs/js/x509.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,29 @@ function is_oid_exist(cert, oid) {
return false;
}

// returns all the matching field with the specified 'oid' as a list
function get_oid_value_all(cert, oid) {

var values = [];

for (var n = 0; n < cert.length; n++) {
if (Array.isArray(cert[n])) {
var r = get_oid_value_all(cert[n], oid);
if (r.length > 0) {
values = values.concat(r);
}
} else {
if (cert[n] == oid) {
if (n < cert.length) {
// push next element in array
values.push(cert[n+1]);
}
}
}
}
return values;
}

function get_oid_value(cert, oid) {
for (var n = 0; n < cert.length; n++) {
if (Array.isArray(cert[n])) {
Expand Down Expand Up @@ -327,4 +350,4 @@ function parse_pem_cert(pem) {
return asn1_read(der);
}

export default {asn1_read, parse_pem_cert, is_oid_exist, get_oid_value};
export default {asn1_read, parse_pem_cert, is_oid_exist, get_oid_value, get_oid_value_all};

0 comments on commit 4935efc

Please sign in to comment.