* Converts an X.509 subject or issuer to an ASN.1 RDNSequence. * * @param {any} obj the subject or issuer (distinguished name). * * @return the ASN.1 RDNSequence.
(obj)
| 14 | * @return the ASN.1 RDNSequence. |
| 15 | */ |
| 16 | function _dnToAsn1(obj) { |
| 17 | // create an empty RDNSequence |
| 18 | const rval = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, []) |
| 19 | |
| 20 | // iterate over attributes |
| 21 | let attr, set |
| 22 | const attrs = obj.attributes |
| 23 | for (let i = 0; i < attrs.length; ++i) { |
| 24 | attr = attrs[i] |
| 25 | let value = attr.value |
| 26 | |
| 27 | // reuse tag class for attribute value if available |
| 28 | let valueTagClass = asn1.Type.PRINTABLESTRING |
| 29 | if ('valueTagClass' in attr) { |
| 30 | valueTagClass = attr.valueTagClass |
| 31 | |
| 32 | if (valueTagClass === asn1.Type.UTF8) { |
| 33 | value = forge.util.encodeUtf8(value) |
| 34 | } |
| 35 | // FIXME: handle more encodings |
| 36 | } |
| 37 | |
| 38 | // create a RelativeDistinguishedName set |
| 39 | // each value in the set is an AttributeTypeAndValue first |
| 40 | // containing the type (an OID) and second the value |
| 41 | set = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [ |
| 42 | asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ |
| 43 | // AttributeType |
| 44 | asn1.create( |
| 45 | asn1.Class.UNIVERSAL, |
| 46 | asn1.Type.OID, |
| 47 | false, |
| 48 | asn1.oidToDer(attr.type).getBytes() |
| 49 | ), |
| 50 | // AttributeValue |
| 51 | asn1.create(asn1.Class.UNIVERSAL, valueTagClass, false, value) |
| 52 | ]) |
| 53 | ]) |
| 54 | rval.value.push(set) |
| 55 | } |
| 56 | |
| 57 | return rval |
| 58 | } |
| 59 | |
| 60 | const jan_1_1950 = new Date('1950-01-01T00:00:00Z') // eslint-disable-line camelcase |
| 61 | const jan_1_2050 = new Date('2050-01-01T00:00:00Z') // eslint-disable-line camelcase |
no outgoing calls
no test coverage detected
searching dependent graphs…