123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- using System;
- using System.Text;
- using Org.BouncyCastle.Utilities;
- namespace Org.BouncyCastle.Asn1
- {
-
- public class DerIA5String
- : DerStringBase
- {
- private readonly string str;
-
- public static DerIA5String GetInstance(
- object obj)
- {
- if (obj == null || obj is DerIA5String)
- {
- return (DerIA5String)obj;
- }
- throw new ArgumentException("illegal object in GetInstance: " + Org.BouncyCastle.Utilities.Platform.GetTypeName(obj));
- }
-
- public static DerIA5String GetInstance(
- Asn1TaggedObject obj,
- bool isExplicit)
- {
- Asn1Object o = obj.GetObject();
- if (isExplicit || o is DerIA5String)
- {
- return GetInstance(o);
- }
- return new DerIA5String(((Asn1OctetString)o).GetOctets());
- }
-
- public DerIA5String(
- byte[] str)
- : this(Strings.FromAsciiByteArray(str), false)
- {
- }
-
- public DerIA5String(
- string str)
- : this(str, false)
- {
- }
-
- public DerIA5String(
- string str,
- bool validate)
- {
- if (str == null)
- throw new ArgumentNullException("str");
- if (validate && !IsIA5String(str))
- throw new ArgumentException("string contains illegal characters", "str");
- this.str = str;
- }
- public override string GetString()
- {
- return str;
- }
- public byte[] GetOctets()
- {
- return Strings.ToAsciiByteArray(str);
- }
- internal override void Encode(
- DerOutputStream derOut)
- {
- derOut.WriteEncoded(Asn1Tags.IA5String, GetOctets());
- }
- protected override int Asn1GetHashCode()
- {
- return this.str.GetHashCode();
- }
- protected override bool Asn1Equals(
- Asn1Object asn1Object)
- {
- DerIA5String other = asn1Object as DerIA5String;
- if (other == null)
- return false;
- return this.str.Equals(other.str);
- }
-
- public static bool IsIA5String(
- string str)
- {
- foreach (char ch in str)
- {
- if (ch > 0x007f)
- {
- return false;
- }
- }
- return true;
- }
- }
- }
- #endif
|