203 lines
4.5 KiB
C#
203 lines
4.5 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Text;
|
|
|
|
namespace Mono.Security.X509.Extensions
|
|
{
|
|
// Token: 0x020000B1 RID: 177
|
|
internal class KeyUsageExtension : X509Extension
|
|
{
|
|
// Token: 0x0600099F RID: 2463 RVA: 0x00027A9C File Offset: 0x00025C9C
|
|
public KeyUsageExtension(ASN1 asn1)
|
|
: base(asn1)
|
|
{
|
|
}
|
|
|
|
// Token: 0x060009A0 RID: 2464 RVA: 0x00027AA8 File Offset: 0x00025CA8
|
|
public KeyUsageExtension(X509Extension extension)
|
|
: base(extension)
|
|
{
|
|
}
|
|
|
|
// Token: 0x060009A1 RID: 2465 RVA: 0x00027AB4 File Offset: 0x00025CB4
|
|
public KeyUsageExtension()
|
|
{
|
|
this.extnOid = "2.5.29.15";
|
|
}
|
|
|
|
// Token: 0x060009A2 RID: 2466 RVA: 0x00027AC8 File Offset: 0x00025CC8
|
|
protected override void Decode()
|
|
{
|
|
ASN1 asn = new ASN1(this.extnValue.Value);
|
|
if (asn.Tag != 3)
|
|
{
|
|
throw new ArgumentException("Invalid KeyUsage extension");
|
|
}
|
|
int i = 1;
|
|
while (i < asn.Value.Length)
|
|
{
|
|
this.kubits = (this.kubits << 8) + (int)asn.Value[i++];
|
|
}
|
|
}
|
|
|
|
// Token: 0x060009A3 RID: 2467 RVA: 0x00027B30 File Offset: 0x00025D30
|
|
protected override void Encode()
|
|
{
|
|
this.extnValue = new ASN1(4);
|
|
ushort num = (ushort)this.kubits;
|
|
if (num > 0)
|
|
{
|
|
byte b;
|
|
for (b = 15; b > 0; b -= 1)
|
|
{
|
|
if ((num & 32768) == 32768)
|
|
{
|
|
break;
|
|
}
|
|
num = (ushort)(num << 1);
|
|
}
|
|
if (this.kubits > 255)
|
|
{
|
|
b -= 8;
|
|
this.extnValue.Add(new ASN1(3, new byte[]
|
|
{
|
|
b,
|
|
(byte)this.kubits,
|
|
(byte)(this.kubits >> 8)
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
this.extnValue.Add(new ASN1(3, new byte[]
|
|
{
|
|
b,
|
|
(byte)this.kubits
|
|
}));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ASN1 extnValue = this.extnValue;
|
|
byte b2 = 3;
|
|
byte[] array = new byte[2];
|
|
array[0] = 7;
|
|
extnValue.Add(new ASN1(b2, array));
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000119 RID: 281
|
|
// (get) Token: 0x060009A4 RID: 2468 RVA: 0x00027C20 File Offset: 0x00025E20
|
|
// (set) Token: 0x060009A5 RID: 2469 RVA: 0x00027C28 File Offset: 0x00025E28
|
|
public KeyUsages KeyUsage
|
|
{
|
|
get
|
|
{
|
|
return (KeyUsages)this.kubits;
|
|
}
|
|
set
|
|
{
|
|
this.kubits = Convert.ToInt32(value, CultureInfo.InvariantCulture);
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700011A RID: 282
|
|
// (get) Token: 0x060009A6 RID: 2470 RVA: 0x00027C40 File Offset: 0x00025E40
|
|
public override string Name
|
|
{
|
|
get
|
|
{
|
|
return "Key Usage";
|
|
}
|
|
}
|
|
|
|
// Token: 0x060009A7 RID: 2471 RVA: 0x00027C48 File Offset: 0x00025E48
|
|
public bool Support(KeyUsages usage)
|
|
{
|
|
int num = Convert.ToInt32(usage, CultureInfo.InvariantCulture);
|
|
return (num & this.kubits) == num;
|
|
}
|
|
|
|
// Token: 0x060009A8 RID: 2472 RVA: 0x00027C74 File Offset: 0x00025E74
|
|
public override string ToString()
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
if (this.Support(KeyUsages.digitalSignature))
|
|
{
|
|
stringBuilder.Append("Digital Signature");
|
|
}
|
|
if (this.Support(KeyUsages.nonRepudiation))
|
|
{
|
|
if (stringBuilder.Length > 0)
|
|
{
|
|
stringBuilder.Append(" , ");
|
|
}
|
|
stringBuilder.Append("Non-Repudiation");
|
|
}
|
|
if (this.Support(KeyUsages.keyEncipherment))
|
|
{
|
|
if (stringBuilder.Length > 0)
|
|
{
|
|
stringBuilder.Append(" , ");
|
|
}
|
|
stringBuilder.Append("Key Encipherment");
|
|
}
|
|
if (this.Support(KeyUsages.dataEncipherment))
|
|
{
|
|
if (stringBuilder.Length > 0)
|
|
{
|
|
stringBuilder.Append(" , ");
|
|
}
|
|
stringBuilder.Append("Data Encipherment");
|
|
}
|
|
if (this.Support(KeyUsages.keyAgreement))
|
|
{
|
|
if (stringBuilder.Length > 0)
|
|
{
|
|
stringBuilder.Append(" , ");
|
|
}
|
|
stringBuilder.Append("Key Agreement");
|
|
}
|
|
if (this.Support(KeyUsages.keyCertSign))
|
|
{
|
|
if (stringBuilder.Length > 0)
|
|
{
|
|
stringBuilder.Append(" , ");
|
|
}
|
|
stringBuilder.Append("Certificate Signing");
|
|
}
|
|
if (this.Support(KeyUsages.cRLSign))
|
|
{
|
|
if (stringBuilder.Length > 0)
|
|
{
|
|
stringBuilder.Append(" , ");
|
|
}
|
|
stringBuilder.Append("CRL Signing");
|
|
}
|
|
if (this.Support(KeyUsages.encipherOnly))
|
|
{
|
|
if (stringBuilder.Length > 0)
|
|
{
|
|
stringBuilder.Append(" , ");
|
|
}
|
|
stringBuilder.Append("Encipher Only ");
|
|
}
|
|
if (this.Support(KeyUsages.decipherOnly))
|
|
{
|
|
if (stringBuilder.Length > 0)
|
|
{
|
|
stringBuilder.Append(" , ");
|
|
}
|
|
stringBuilder.Append("Decipher Only");
|
|
}
|
|
stringBuilder.Append("(");
|
|
stringBuilder.Append(this.kubits.ToString("X2", CultureInfo.InvariantCulture));
|
|
stringBuilder.Append(")");
|
|
stringBuilder.Append(Environment.NewLine);
|
|
return stringBuilder.ToString();
|
|
}
|
|
|
|
// Token: 0x04000238 RID: 568
|
|
private int kubits;
|
|
}
|
|
}
|