using System;
using System.Collections.Generic;
using System.Text;
using Mono.Security;
namespace System.Security.Cryptography.X509Certificates
{
/// Defines the collection of object identifiers (OIDs) that indicates the applications that use the key. This class cannot be inherited.
// Token: 0x02000294 RID: 660
public sealed class X509EnhancedKeyUsageExtension : X509Extension
{
/// Initializes a new instance of the class.
// Token: 0x06001857 RID: 6231 RVA: 0x00052A48 File Offset: 0x00050C48
public X509EnhancedKeyUsageExtension()
{
this._oid = new Oid("2.5.29.37", "Enhanced Key Usage");
}
/// Initializes a new instance of the class using an object and a value that identifies whether the extension is critical.
/// The encoded data to use to create the extension.
/// true if the extension is critical; otherwise, false.
// Token: 0x06001858 RID: 6232 RVA: 0x00052A68 File Offset: 0x00050C68
public X509EnhancedKeyUsageExtension(AsnEncodedData encodedEnhancedKeyUsages, bool critical)
{
this._oid = new Oid("2.5.29.37", "Enhanced Key Usage");
this._raw = encodedEnhancedKeyUsages.RawData;
base.Critical = critical;
this._status = this.Decode(base.RawData);
}
/// Initializes a new instance of the class using an and a value that identifies whether the extension is critical.
/// An collection.
/// true if the extension is critical; otherwise, false.
/// The specified contains one or more corrupt values.
// Token: 0x06001859 RID: 6233 RVA: 0x00052AB8 File Offset: 0x00050CB8
public X509EnhancedKeyUsageExtension(OidCollection enhancedKeyUsages, bool critical)
{
if (enhancedKeyUsages == null)
{
throw new ArgumentNullException("enhancedKeyUsages");
}
this._oid = new Oid("2.5.29.37", "Enhanced Key Usage");
base.Critical = critical;
this._enhKeyUsage = enhancedKeyUsages.ReadOnlyCopy();
base.RawData = this.Encode();
}
/// Gets the collection of object identifiers (OIDs) that indicate the applications that use the key.
/// An object indicating the applications that use the key.
///
///
///
// Token: 0x170007A8 RID: 1960
// (get) Token: 0x0600185A RID: 6234 RVA: 0x00052B10 File Offset: 0x00050D10
public OidCollection EnhancedKeyUsages
{
get
{
AsnDecodeStatus status = this._status;
if (status != AsnDecodeStatus.Ok && status != AsnDecodeStatus.InformationNotAvailable)
{
throw new CryptographicException("Badly encoded extension.");
}
if (this._enhKeyUsage == null)
{
this._enhKeyUsage = new OidCollection();
}
this._enhKeyUsage.ReadOnly = true;
return this._enhKeyUsage;
}
}
/// Initializes a new instance of the class using an object.
/// The encoded data to use to create the extension.
// Token: 0x0600185B RID: 6235 RVA: 0x00052B6C File Offset: 0x00050D6C
public override void CopyFrom(AsnEncodedData asnEncodedData)
{
if (asnEncodedData == null)
{
throw new ArgumentNullException("encodedData");
}
X509Extension x509Extension = asnEncodedData as X509Extension;
if (x509Extension == null)
{
throw new ArgumentException(global::Locale.GetText("Wrong type."), "asnEncodedData");
}
if (x509Extension._oid == null)
{
this._oid = new Oid("2.5.29.37", "Enhanced Key Usage");
}
else
{
this._oid = new Oid(x509Extension._oid);
}
base.RawData = x509Extension.RawData;
base.Critical = x509Extension.Critical;
this._status = this.Decode(base.RawData);
}
// Token: 0x0600185C RID: 6236 RVA: 0x00052C0C File Offset: 0x00050E0C
internal AsnDecodeStatus Decode(byte[] extension)
{
if (extension == null || extension.Length == 0)
{
return AsnDecodeStatus.BadAsn;
}
if (extension[0] != 48)
{
return AsnDecodeStatus.BadTag;
}
if (this._enhKeyUsage == null)
{
this._enhKeyUsage = new OidCollection();
}
try
{
ASN1 asn = new ASN1(extension);
if (asn.Tag != 48)
{
throw new CryptographicException(global::Locale.GetText("Invalid ASN.1 Tag"));
}
for (int i = 0; i < asn.Count; i++)
{
this._enhKeyUsage.Add(new Oid(ASN1Convert.ToOid(asn[i])));
}
}
catch
{
return AsnDecodeStatus.BadAsn;
}
return AsnDecodeStatus.Ok;
}
// Token: 0x0600185D RID: 6237 RVA: 0x00052CD4 File Offset: 0x00050ED4
internal byte[] Encode()
{
ASN1 asn = new ASN1(48);
foreach (Oid oid in this._enhKeyUsage)
{
asn.Add(ASN1Convert.FromOid(oid.Value));
}
return asn.GetBytes();
}
// Token: 0x0600185E RID: 6238 RVA: 0x00052D24 File Offset: 0x00050F24
internal override string ToString(bool multiLine)
{
switch (this._status)
{
case AsnDecodeStatus.BadAsn:
return string.Empty;
case AsnDecodeStatus.BadTag:
case AsnDecodeStatus.BadLength:
return base.FormatUnkownData(this._raw);
case AsnDecodeStatus.InformationNotAvailable:
return "Information Not Available";
default:
{
if (this._oid.Value != "2.5.29.37")
{
return string.Format("Unknown Key Usage ({0})", this._oid.Value);
}
if (this._enhKeyUsage.Count == 0)
{
return "Information Not Available";
}
StringBuilder stringBuilder = new StringBuilder();
int i = 0;
while (i < this._enhKeyUsage.Count)
{
Oid oid = this._enhKeyUsage[i];
string value = oid.Value;
if (value == null)
{
goto IL_102;
}
if (X509EnhancedKeyUsageExtension.<>f__switch$mapE == null)
{
X509EnhancedKeyUsageExtension.<>f__switch$mapE = new Dictionary(1) { { "1.3.6.1.5.5.7.3.1", 0 } };
}
int num;
if (!X509EnhancedKeyUsageExtension.<>f__switch$mapE.TryGetValue(value, out num))
{
goto IL_102;
}
if (num != 0)
{
goto IL_102;
}
stringBuilder.Append("Server Authentication (");
IL_113:
stringBuilder.Append(oid.Value);
stringBuilder.Append(")");
if (multiLine)
{
stringBuilder.Append(Environment.NewLine);
}
else if (i != this._enhKeyUsage.Count - 1)
{
stringBuilder.Append(", ");
}
i++;
continue;
IL_102:
stringBuilder.Append("Unknown Key Usage (");
goto IL_113;
}
return stringBuilder.ToString();
}
}
}
// Token: 0x0400133E RID: 4926
internal const string oid = "2.5.29.37";
// Token: 0x0400133F RID: 4927
internal const string friendlyName = "Enhanced Key Usage";
// Token: 0x04001340 RID: 4928
private OidCollection _enhKeyUsage;
// Token: 0x04001341 RID: 4929
private AsnDecodeStatus _status;
}
}