code: function _CRIAttributesToAsn1(csr) {
    // create an empty context-specific container
    var rval = asn1.create(asn1.Class.CONTEXT_SPECIFIC, 0, true, []);
  
    // no attributes, return empty container
    if(csr.attributes.length === 0) {
      return rval;
    }
  
    // each attribute has a sequence with a type and a set of values
    var attrs = csr.attributes;
    for(var i = 0; i < attrs.length; ++i) {
      var attr = attrs[i];
      var value = attr.value;
  
      // reuse tag class for attribute value if available
      var valueTagClass = asn1.Type.UTF8;
      if('valueTagClass' in attr) {
        valueTagClass = attr.valueTagClass;
      }
      if(valueTagClass === asn1.Type.UTF8) {
        value = forge.util.encodeUtf8(value);
      }
      // FIXME: handle more encodings
  
      // create a RelativeDistinguishedName set
      // each value in the set is an AttributeTypeAndValue first
      // containing the type (an OID) and second the value
      var seq = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
        // AttributeType
        asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
          asn1.oidToDer(attr.type).getBytes()),
        asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SET, true, [
          // AttributeValue
          asn1.create(asn1.Class.UNIVERSAL, valueTagClass, false, value)
        ])
      ]);
      rval.value.push(seq);
    }
  
    return rval;
  }
docs: Converts a certification request's attributes to an ASN.1 set of
  CRIAttributes.
  
  @param csr certification request.
  
  @return the ASN.1 set of CRIAttributes.