Example #1
0
        /**
         * Creates a new <code>DisplayText</code> instance.
         *
         * @param type the desired encoding type for the text.
         * @param text the text to store. Strings longer than 200
         * characters are truncated.
         */
        public DisplayText(int type, string text)
        {
            if (text.Length > DISPLAY_TEXT_MAXIMUM_SIZE)
            {
                // RFC3280 limits these strings to 200 chars
                // truncate the string
                text = text.Substring(0, DISPLAY_TEXT_MAXIMUM_SIZE);
            }

            contentType = type;
            switch (type)
            {
            case CONTENT_TYPE_IA5STRING:
                contents = (DERString) new DERIA5String(text);
                break;

            case CONTENT_TYPE_UTF8STRING:
                contents = (DERString) new DERUTF8String(text);
                break;

            case CONTENT_TYPE_VISIBLESTRING:
                contents = (DERString) new DERVisibleString(text);
                break;

            case CONTENT_TYPE_BMPSTRING:
                contents = (DERString) new DERBMPString(text);
                break;

            default:
                contents = (DERString) new DERUTF8String(text);
                break;
            }
        }
Example #2
0
        /**
         * Creates a new <code>DisplayText</code> instance.
         *
         * @param text the text to encapsulate. Strings longer than 200
         * characters are truncated.
         */
        public DisplayText(string text)
        {
            // by default use UTF8String
            if (text.Length > DISPLAY_TEXT_MAXIMUM_SIZE)
            {
                text = text.Substring(0, DISPLAY_TEXT_MAXIMUM_SIZE);
            }

            if (canBeUTF8(text))
            {
                contentType = CONTENT_TYPE_UTF8STRING;
                contents    = new DERUTF8String(text);
            }
            else
            {
                contentType = CONTENT_TYPE_BMPSTRING;
                contents    = new DERBMPString(text);
            }
        }
Example #3
0
 /**
  * Creates a new <code>DisplayText</code> instance.
  * <p>Useful when reading back a <code>DisplayText</code> class
  * from it's ASN1Encodable form.
  *
  * @param de a <code>ASN1Encodable</code> instance.
  */
 public DisplayText(DERString de)
 {
     contents = de;
 }