Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/sshpk/lib/identity.js')
-rw-r--r--node_modules/sshpk/lib/identity.js90
1 files changed, 87 insertions, 3 deletions
diff --git a/node_modules/sshpk/lib/identity.js b/node_modules/sshpk/lib/identity.js
index 495b83a6c..7d75b6671 100644
--- a/node_modules/sshpk/lib/identity.js
+++ b/node_modules/sshpk/lib/identity.js
@@ -24,9 +24,21 @@ oids.l = '2.5.4.7';
oids.s = '2.5.4.8';
oids.c = '2.5.4.6';
oids.sn = '2.5.4.4';
+oids.postalCode = '2.5.4.17';
+oids.serialNumber = '2.5.4.5';
+oids.street = '2.5.4.9';
+oids.x500UniqueIdentifier = '2.5.4.45';
+oids.role = '2.5.4.72';
+oids.telephoneNumber = '2.5.4.20';
+oids.description = '2.5.4.13';
oids.dc = '0.9.2342.19200300.100.1.25';
oids.uid = '0.9.2342.19200300.100.1.1';
oids.mail = '0.9.2342.19200300.100.1.3';
+oids.title = '2.5.4.12';
+oids.gn = '2.5.4.42';
+oids.initials = '2.5.4.43';
+oids.pseudonym = '2.5.4.65';
+oids.emailAddress = '1.2.840.113549.1.9.1';
var unoids = {};
Object.keys(oids).forEach(function (k) {
@@ -113,10 +125,39 @@ function Identity(opts) {
Identity.prototype.toString = function () {
return (this.components.map(function (c) {
- return (c.name.toUpperCase() + '=' + c.value);
+ var n = c.name.toUpperCase();
+ /*JSSTYLED*/
+ n = n.replace(/=/g, '\\=');
+ var v = c.value;
+ /*JSSTYLED*/
+ v = v.replace(/,/g, '\\,');
+ return (n + '=' + v);
}).join(', '));
};
+Identity.prototype.get = function (name, asArray) {
+ assert.string(name, 'name');
+ var arr = this.componentLookup[name];
+ if (arr === undefined || arr.length === 0)
+ return (undefined);
+ if (!asArray && arr.length > 1)
+ throw (new Error('Multiple values for attribute ' + name));
+ if (!asArray)
+ return (arr[0].value);
+ return (arr.map(function (c) {
+ return (c.value);
+ }));
+};
+
+Identity.prototype.toArray = function (idx) {
+ return (this.components.map(function (c) {
+ return ({
+ name: c.name,
+ value: c.value
+ });
+ }));
+};
+
/*
* These are from X.680 -- PrintableString allowed chars are in section 37.4
* table 8. Spec for IA5Strings is "1,6 + SPACE + DEL" where 1 refers to
@@ -224,17 +265,60 @@ Identity.forEmail = function (email) {
Identity.parseDN = function (dn) {
assert.string(dn, 'dn');
- var parts = dn.split(',');
+ var parts = [''];
+ var idx = 0;
+ var rem = dn;
+ while (rem.length > 0) {
+ var m;
+ /*JSSTYLED*/
+ if ((m = /^,/.exec(rem)) !== null) {
+ parts[++idx] = '';
+ rem = rem.slice(m[0].length);
+ /*JSSTYLED*/
+ } else if ((m = /^\\,/.exec(rem)) !== null) {
+ parts[idx] += ',';
+ rem = rem.slice(m[0].length);
+ /*JSSTYLED*/
+ } else if ((m = /^\\./.exec(rem)) !== null) {
+ parts[idx] += m[0];
+ rem = rem.slice(m[0].length);
+ /*JSSTYLED*/
+ } else if ((m = /^[^\\,]+/.exec(rem)) !== null) {
+ parts[idx] += m[0];
+ rem = rem.slice(m[0].length);
+ } else {
+ throw (new Error('Failed to parse DN'));
+ }
+ }
var cmps = parts.map(function (c) {
c = c.trim();
var eqPos = c.indexOf('=');
- var name = c.slice(0, eqPos).toLowerCase();
+ while (eqPos > 0 && c.charAt(eqPos - 1) === '\\')
+ eqPos = c.indexOf('=', eqPos + 1);
+ if (eqPos === -1) {
+ throw (new Error('Failed to parse DN'));
+ }
+ /*JSSTYLED*/
+ var name = c.slice(0, eqPos).toLowerCase().replace(/\\=/g, '=');
var value = c.slice(eqPos + 1);
return ({ name: name, value: value });
});
return (new Identity({ components: cmps }));
};
+Identity.fromArray = function (components) {
+ assert.arrayOfObject(components, 'components');
+ components.forEach(function (cmp) {
+ assert.object(cmp, 'component');
+ assert.string(cmp.name, 'component.name');
+ if (!Buffer.isBuffer(cmp.value) &&
+ !(typeof (cmp.value) === 'string')) {
+ throw (new Error('Invalid component value'));
+ }
+ });
+ return (new Identity({ components: components }));
+};
+
Identity.parseAsn1 = function (der, top) {
var components = [];
der.readSequence(top);