Beispiel #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 > DisplayTextMaximumSize)
			{
				// RFC3280 limits these strings to 200 chars
				// truncate the string
				text = text.Substring(0, DisplayTextMaximumSize);
			}

			contentType = type;
			switch (type)
			{
				case ContentTypeIA5String:
					contents = (IAsn1String)new DerIA5String (text);
					break;
				case ContentTypeUtf8String:
					contents = (IAsn1String)new DerUtf8String(text);
					break;
				case ContentTypeVisibleString:
					contents = (IAsn1String)new DerVisibleString(text);
					break;
				case ContentTypeBmpString:
					contents = (IAsn1String)new DerBmpString(text);
					break;
				default:
					contents = (IAsn1String)new DerUtf8String(text);
					break;
			}
		}
Beispiel #2
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 > DisplayTextMaximumSize)
            {
                // RFC3280 limits these strings to 200 chars
                // truncate the string
                text = text.Substring(0, DisplayTextMaximumSize);
            }

            contentType = type;
            switch (type)
            {
            case ContentTypeIA5String:
                contents = (IAsn1String) new DerIA5String(text);
                break;

            case ContentTypeUtf8String:
                contents = (IAsn1String) new DerUtf8String(text);
                break;

            case ContentTypeVisibleString:
                contents = (IAsn1String) new DerVisibleString(text);
                break;

            case ContentTypeBmpString:
                contents = (IAsn1String) new DerBmpString(text);
                break;

            default:
                contents = (IAsn1String) new DerUtf8String(text);
                break;
            }
        }
        private void EncodingCheck(byte[] derData, byte[] dlData)
        {
            if (Arrays.AreEqual(derData, Asn1Object.FromByteArray(dlData).GetEncoded()))
            {
                //Fail("failed DL check");
                Fail("failed BER check");
            }
            IAsn1String dl = BerBitString.GetInstance(dlData);

            //IsTrue("DL test failed", dl is DLBitString);
            IsTrue("BER test failed", dl is BerBitString);
            if (!Arrays.AreEqual(derData, Asn1Object.FromByteArray(dlData).GetDerEncoded()))
            {
                Fail("failed DER check");
            }
            // TODO This test isn't applicable until we get the DL variants
            //try
            //{
            //    DerBitString.GetInstance(dlData);
            //    Fail("no exception");
            //}
            //catch (ArgumentException e)
            //{
            //    // ignore
            //}
            IAsn1String der = DerBitString.GetInstance(derData);

            IsTrue("DER test failed", der is DerBitString);
        }
Beispiel #4
0
        public DisplayText(int type, string text)
        {
            if (text.get_Length() > 200)
            {
                text = text.Substring(0, 200);
            }
            contentType = type;
            switch (type)
            {
            case 0:
                contents = new DerIA5String(text);
                break;

            case 2:
                contents = new DerUtf8String(text);
                break;

            case 3:
                contents = new DerVisibleString(text);
                break;

            case 1:
                contents = new DerBmpString(text);
                break;

            default:
                contents = new DerUtf8String(text);
                break;
            }
        }
        private void checkConstruction(
            NameOrPseudonym id,
            string pseudonym,
            DirectoryString surname,
            Asn1Sequence givenName)
        {
            checkValues(id, pseudonym, surname, givenName);

            id = NameOrPseudonym.GetInstance(id);

            checkValues(id, pseudonym, surname, givenName);

            Asn1InputStream aIn = new Asn1InputStream(id.ToAsn1Object().GetEncoded());

            if (surname != null)
            {
                Asn1Sequence seq = (Asn1Sequence)aIn.ReadObject();

                id = NameOrPseudonym.GetInstance(seq);
            }
            else
            {
                IAsn1String s = (IAsn1String)aIn.ReadObject();

                id = NameOrPseudonym.GetInstance(s);
            }

            checkValues(id, pseudonym, surname, givenName);
        }
Beispiel #6
0
        public DisplayText(int type, string text)
        {
            if (text.Length > 200)
            {
                text = text.Substring(0, 200);
            }
            this.contentType = type;
            switch (type)
            {
            case 0:
                this.contents = new DerIA5String(text);
                return;

            case 1:
                this.contents = new DerBmpString(text);
                return;

            case 2:
                this.contents = new DerUtf8String(text);
                return;

            case 3:
                this.contents = new DerVisibleString(text);
                return;

            default:
                this.contents = new DerUtf8String(text);
                return;
            }
        }
Beispiel #7
0
 public DisplayText(string text)
 {
     if (text.get_Length() > 200)
     {
         text = text.Substring(0, 200);
     }
     contentType = 2;
     contents    = new DerUtf8String(text);
 }
Beispiel #8
0
 public DisplayText(string text)
 {
     if (text.Length > 200)
     {
         text = text.Substring(0, 200);
     }
     this.contentType = 2;
     this.contents    = new DerUtf8String(text);
 }
Beispiel #9
0
//		/**
//		 * return true if the passed in string can be represented without
//		 * loss as a PrintableString, false otherwise.
//		 */
//		private bool CanBePrintable(
//			string str)
//		{
//			for (int i = str.Length - 1; i >= 0; i--)
//			{
//				if (str[i] > 0x007f)
//				{
//					return false;
//				}
//			}
//
//			return true;
//		}

        /**
         * 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 > DisplayTextMaximumSize)
            {
                text = text.Substring(0, DisplayTextMaximumSize);
            }

            contentType = ContentTypeUtf8String;
            contents    = new DerUtf8String(text);
        }
Beispiel #10
0
        private void checkConstruction(
            Restriction restriction,
            DirectoryString res)
        {
            checkValues(restriction, res);

            restriction = Restriction.GetInstance(restriction);

            checkValues(restriction, res);

            Asn1InputStream aIn = new Asn1InputStream(restriction.ToAsn1Object().GetEncoded());

            IAsn1String str = (IAsn1String)aIn.ReadObject();

            restriction = Restriction.GetInstance(str);

            checkValues(restriction, res);
        }
Beispiel #11
0
        private void checkConstruction(
            AdditionalInformationSyntax syntax,
            DirectoryString information)
        {
            checkValues(syntax, information);

            syntax = AdditionalInformationSyntax.GetInstance(syntax);

            checkValues(syntax, information);

            Asn1InputStream aIn = new Asn1InputStream(syntax.ToAsn1Object().GetEncoded());

            IAsn1String info = (IAsn1String)aIn.ReadObject();

            syntax = AdditionalInformationSyntax.GetInstance(info);

            checkValues(syntax, information);
        }
Beispiel #12
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(IAsn1String de)
 {
     contents = de;
 }
Beispiel #13
0
		/**
		 * Creates a new <code>DisplayText</code> instance.
		 * <p>Useful when reading back a <code>DisplayText</code> class
		 * from it's Asn1Encodable form.</p>
		 *
		 * @param contents an <code>Asn1Encodable</code> instance.
		 */
		public DisplayText(
			IAsn1String contents)
		{
			this.contents = contents;
		}
Beispiel #14
0
//		/**
//		 * return true if the passed in string can be represented without
//		 * loss as a PrintableString, false otherwise.
//		 */
//		private bool CanBePrintable(
//			string str)
//		{
//			for (int i = str.Length - 1; i >= 0; i--)
//			{
//				if (str[i] > 0x007f)
//				{
//					return false;
//				}
//			}
//
//			return true;
//		}

		/**
		 * 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 > DisplayTextMaximumSize)
			{
				text = text.Substring(0, DisplayTextMaximumSize);
			}

			contentType = ContentTypeUtf8String;
			contents = new DerUtf8String(text);
		}
Beispiel #15
0
 public DisplayText(IAsn1String contents)
 {
     this.contents = contents;
 }