init commit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Ess;
|
||||
|
||||
public class ContentHints : Asn1Encodable
|
||||
{
|
||||
private readonly DerUtf8String contentDescription;
|
||||
|
||||
private readonly DerObjectIdentifier contentType;
|
||||
|
||||
public DerObjectIdentifier ContentType => contentType;
|
||||
|
||||
public DerUtf8String ContentDescription => contentDescription;
|
||||
|
||||
public static ContentHints GetInstance(object o)
|
||||
{
|
||||
if (o == null || o is ContentHints)
|
||||
{
|
||||
return (ContentHints)o;
|
||||
}
|
||||
if (o is Asn1Sequence)
|
||||
{
|
||||
return new ContentHints((Asn1Sequence)o);
|
||||
}
|
||||
throw new ArgumentException("unknown object in 'ContentHints' factory : " + Platform.GetTypeName(o) + ".");
|
||||
}
|
||||
|
||||
private ContentHints(Asn1Sequence seq)
|
||||
{
|
||||
IAsn1Convertible asn1Convertible = seq[0];
|
||||
if (asn1Convertible.ToAsn1Object() is DerUtf8String)
|
||||
{
|
||||
contentDescription = DerUtf8String.GetInstance(asn1Convertible);
|
||||
contentType = DerObjectIdentifier.GetInstance(seq[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
contentType = DerObjectIdentifier.GetInstance(seq[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public ContentHints(DerObjectIdentifier contentType)
|
||||
{
|
||||
this.contentType = contentType;
|
||||
contentDescription = null;
|
||||
}
|
||||
|
||||
public ContentHints(DerObjectIdentifier contentType, DerUtf8String contentDescription)
|
||||
{
|
||||
this.contentType = contentType;
|
||||
this.contentDescription = contentDescription;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (contentDescription != null)
|
||||
{
|
||||
asn1EncodableVector.Add(contentDescription);
|
||||
}
|
||||
asn1EncodableVector.Add(contentType);
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Ess;
|
||||
|
||||
public class ContentIdentifier : Asn1Encodable
|
||||
{
|
||||
private Asn1OctetString value;
|
||||
|
||||
public Asn1OctetString Value => value;
|
||||
|
||||
public static ContentIdentifier GetInstance(object o)
|
||||
{
|
||||
if (o == null || o is ContentIdentifier)
|
||||
{
|
||||
return (ContentIdentifier)o;
|
||||
}
|
||||
if (o is Asn1OctetString)
|
||||
{
|
||||
return new ContentIdentifier((Asn1OctetString)o);
|
||||
}
|
||||
throw new ArgumentException("unknown object in 'ContentIdentifier' factory : " + Platform.GetTypeName(o) + ".");
|
||||
}
|
||||
|
||||
public ContentIdentifier(Asn1OctetString value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public ContentIdentifier(byte[] value)
|
||||
: this(new DerOctetString(value))
|
||||
{
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Ess;
|
||||
|
||||
public class EssCertID : Asn1Encodable
|
||||
{
|
||||
private Asn1OctetString certHash;
|
||||
|
||||
private IssuerSerial issuerSerial;
|
||||
|
||||
public IssuerSerial IssuerSerial => issuerSerial;
|
||||
|
||||
public static EssCertID GetInstance(object o)
|
||||
{
|
||||
if (o == null || o is EssCertID)
|
||||
{
|
||||
return (EssCertID)o;
|
||||
}
|
||||
if (o is Asn1Sequence)
|
||||
{
|
||||
return new EssCertID((Asn1Sequence)o);
|
||||
}
|
||||
throw new ArgumentException("unknown object in 'EssCertID' factory : " + Platform.GetTypeName(o) + ".");
|
||||
}
|
||||
|
||||
public EssCertID(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 1 || seq.Count > 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
certHash = Asn1OctetString.GetInstance(seq[0]);
|
||||
if (seq.Count > 1)
|
||||
{
|
||||
issuerSerial = IssuerSerial.GetInstance(seq[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public EssCertID(byte[] hash)
|
||||
{
|
||||
certHash = new DerOctetString(hash);
|
||||
}
|
||||
|
||||
public EssCertID(byte[] hash, IssuerSerial issuerSerial)
|
||||
{
|
||||
certHash = new DerOctetString(hash);
|
||||
this.issuerSerial = issuerSerial;
|
||||
}
|
||||
|
||||
public byte[] GetCertHash()
|
||||
{
|
||||
return certHash.GetOctets();
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(certHash);
|
||||
if (issuerSerial != null)
|
||||
{
|
||||
asn1EncodableVector.Add(issuerSerial);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.Nist;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Ess;
|
||||
|
||||
public class EssCertIDv2 : Asn1Encodable
|
||||
{
|
||||
private readonly AlgorithmIdentifier hashAlgorithm;
|
||||
|
||||
private readonly byte[] certHash;
|
||||
|
||||
private readonly IssuerSerial issuerSerial;
|
||||
|
||||
private static readonly AlgorithmIdentifier DefaultAlgID = new AlgorithmIdentifier(NistObjectIdentifiers.IdSha256);
|
||||
|
||||
public AlgorithmIdentifier HashAlgorithm => hashAlgorithm;
|
||||
|
||||
public IssuerSerial IssuerSerial => issuerSerial;
|
||||
|
||||
public static EssCertIDv2 GetInstance(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (obj is EssCertIDv2 result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return new EssCertIDv2(Asn1Sequence.GetInstance(obj));
|
||||
}
|
||||
|
||||
private EssCertIDv2(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count > 3)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
|
||||
}
|
||||
int num = 0;
|
||||
if (seq[0] is Asn1OctetString)
|
||||
{
|
||||
hashAlgorithm = DefaultAlgID;
|
||||
}
|
||||
else
|
||||
{
|
||||
hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[num++].ToAsn1Object());
|
||||
}
|
||||
certHash = Asn1OctetString.GetInstance(seq[num++].ToAsn1Object()).GetOctets();
|
||||
if (seq.Count > num)
|
||||
{
|
||||
issuerSerial = IssuerSerial.GetInstance(Asn1Sequence.GetInstance(seq[num].ToAsn1Object()));
|
||||
}
|
||||
}
|
||||
|
||||
public EssCertIDv2(byte[] certHash)
|
||||
: this(null, certHash, null)
|
||||
{
|
||||
}
|
||||
|
||||
public EssCertIDv2(AlgorithmIdentifier algId, byte[] certHash)
|
||||
: this(algId, certHash, null)
|
||||
{
|
||||
}
|
||||
|
||||
public EssCertIDv2(byte[] certHash, IssuerSerial issuerSerial)
|
||||
: this(null, certHash, issuerSerial)
|
||||
{
|
||||
}
|
||||
|
||||
public EssCertIDv2(AlgorithmIdentifier algId, byte[] certHash, IssuerSerial issuerSerial)
|
||||
{
|
||||
if (algId == null)
|
||||
{
|
||||
hashAlgorithm = DefaultAlgID;
|
||||
}
|
||||
else
|
||||
{
|
||||
hashAlgorithm = algId;
|
||||
}
|
||||
this.certHash = certHash;
|
||||
this.issuerSerial = issuerSerial;
|
||||
}
|
||||
|
||||
public byte[] GetCertHash()
|
||||
{
|
||||
return Arrays.Clone(certHash);
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
|
||||
if (!hashAlgorithm.Equals(DefaultAlgID))
|
||||
{
|
||||
asn1EncodableVector.Add(hashAlgorithm);
|
||||
}
|
||||
asn1EncodableVector.Add(new DerOctetString(certHash).ToAsn1Object());
|
||||
if (issuerSerial != null)
|
||||
{
|
||||
asn1EncodableVector.Add(issuerSerial);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.Oiw;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Ess;
|
||||
|
||||
[Obsolete("Use version in Asn1.Esf instead")]
|
||||
public class OtherCertID : Asn1Encodable
|
||||
{
|
||||
private Asn1Encodable otherCertHash;
|
||||
|
||||
private IssuerSerial issuerSerial;
|
||||
|
||||
public AlgorithmIdentifier AlgorithmHash
|
||||
{
|
||||
get
|
||||
{
|
||||
if (otherCertHash.ToAsn1Object() is Asn1OctetString)
|
||||
{
|
||||
return new AlgorithmIdentifier(OiwObjectIdentifiers.IdSha1);
|
||||
}
|
||||
return DigestInfo.GetInstance(otherCertHash).AlgorithmID;
|
||||
}
|
||||
}
|
||||
|
||||
public IssuerSerial IssuerSerial => issuerSerial;
|
||||
|
||||
public static OtherCertID GetInstance(object o)
|
||||
{
|
||||
if (o == null || o is OtherCertID)
|
||||
{
|
||||
return (OtherCertID)o;
|
||||
}
|
||||
if (o is Asn1Sequence)
|
||||
{
|
||||
return new OtherCertID((Asn1Sequence)o);
|
||||
}
|
||||
throw new ArgumentException("unknown object in 'OtherCertID' factory : " + Platform.GetTypeName(o) + ".");
|
||||
}
|
||||
|
||||
public OtherCertID(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 1 || seq.Count > 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
if (seq[0].ToAsn1Object() is Asn1OctetString)
|
||||
{
|
||||
otherCertHash = Asn1OctetString.GetInstance(seq[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
otherCertHash = DigestInfo.GetInstance(seq[0]);
|
||||
}
|
||||
if (seq.Count > 1)
|
||||
{
|
||||
issuerSerial = IssuerSerial.GetInstance(Asn1Sequence.GetInstance(seq[1]));
|
||||
}
|
||||
}
|
||||
|
||||
public OtherCertID(AlgorithmIdentifier algId, byte[] digest)
|
||||
{
|
||||
otherCertHash = new DigestInfo(algId, digest);
|
||||
}
|
||||
|
||||
public OtherCertID(AlgorithmIdentifier algId, byte[] digest, IssuerSerial issuerSerial)
|
||||
{
|
||||
otherCertHash = new DigestInfo(algId, digest);
|
||||
this.issuerSerial = issuerSerial;
|
||||
}
|
||||
|
||||
public byte[] GetCertHash()
|
||||
{
|
||||
if (otherCertHash.ToAsn1Object() is Asn1OctetString)
|
||||
{
|
||||
return ((Asn1OctetString)otherCertHash.ToAsn1Object()).GetOctets();
|
||||
}
|
||||
return DigestInfo.GetInstance(otherCertHash).GetDigest();
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(otherCertHash);
|
||||
if (issuerSerial != null)
|
||||
{
|
||||
asn1EncodableVector.Add(issuerSerial);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Ess;
|
||||
|
||||
[Obsolete("Use version in Asn1.Esf instead")]
|
||||
public class OtherSigningCertificate : Asn1Encodable
|
||||
{
|
||||
private Asn1Sequence certs;
|
||||
|
||||
private Asn1Sequence policies;
|
||||
|
||||
public static OtherSigningCertificate GetInstance(object o)
|
||||
{
|
||||
if (o == null || o is OtherSigningCertificate)
|
||||
{
|
||||
return (OtherSigningCertificate)o;
|
||||
}
|
||||
if (o is Asn1Sequence)
|
||||
{
|
||||
return new OtherSigningCertificate((Asn1Sequence)o);
|
||||
}
|
||||
throw new ArgumentException("unknown object in 'OtherSigningCertificate' factory : " + Platform.GetTypeName(o) + ".");
|
||||
}
|
||||
|
||||
public OtherSigningCertificate(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 1 || seq.Count > 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
certs = Asn1Sequence.GetInstance(seq[0]);
|
||||
if (seq.Count > 1)
|
||||
{
|
||||
policies = Asn1Sequence.GetInstance(seq[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public OtherSigningCertificate(OtherCertID otherCertID)
|
||||
{
|
||||
certs = new DerSequence(otherCertID);
|
||||
}
|
||||
|
||||
public OtherCertID[] GetCerts()
|
||||
{
|
||||
OtherCertID[] array = new OtherCertID[certs.Count];
|
||||
for (int i = 0; i != certs.Count; i++)
|
||||
{
|
||||
array[i] = OtherCertID.GetInstance(certs[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public PolicyInformation[] GetPolicies()
|
||||
{
|
||||
if (policies == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
PolicyInformation[] array = new PolicyInformation[policies.Count];
|
||||
for (int i = 0; i != policies.Count; i++)
|
||||
{
|
||||
array[i] = PolicyInformation.GetInstance(policies[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(certs);
|
||||
if (policies != null)
|
||||
{
|
||||
asn1EncodableVector.Add(policies);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Ess;
|
||||
|
||||
public class SigningCertificate : Asn1Encodable
|
||||
{
|
||||
private Asn1Sequence certs;
|
||||
|
||||
private Asn1Sequence policies;
|
||||
|
||||
public static SigningCertificate GetInstance(object o)
|
||||
{
|
||||
if (o == null || o is SigningCertificate)
|
||||
{
|
||||
return (SigningCertificate)o;
|
||||
}
|
||||
if (o is Asn1Sequence)
|
||||
{
|
||||
return new SigningCertificate((Asn1Sequence)o);
|
||||
}
|
||||
throw new ArgumentException("unknown object in 'SigningCertificate' factory : " + Platform.GetTypeName(o) + ".");
|
||||
}
|
||||
|
||||
public SigningCertificate(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 1 || seq.Count > 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count);
|
||||
}
|
||||
certs = Asn1Sequence.GetInstance(seq[0]);
|
||||
if (seq.Count > 1)
|
||||
{
|
||||
policies = Asn1Sequence.GetInstance(seq[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public SigningCertificate(EssCertID essCertID)
|
||||
{
|
||||
certs = new DerSequence(essCertID);
|
||||
}
|
||||
|
||||
public EssCertID[] GetCerts()
|
||||
{
|
||||
EssCertID[] array = new EssCertID[certs.Count];
|
||||
for (int i = 0; i != certs.Count; i++)
|
||||
{
|
||||
array[i] = EssCertID.GetInstance(certs[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public PolicyInformation[] GetPolicies()
|
||||
{
|
||||
if (policies == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
PolicyInformation[] array = new PolicyInformation[policies.Count];
|
||||
for (int i = 0; i != policies.Count; i++)
|
||||
{
|
||||
array[i] = PolicyInformation.GetInstance(policies[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(certs);
|
||||
if (policies != null)
|
||||
{
|
||||
asn1EncodableVector.Add(policies);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Ess;
|
||||
|
||||
public class SigningCertificateV2 : Asn1Encodable
|
||||
{
|
||||
private readonly Asn1Sequence certs;
|
||||
|
||||
private readonly Asn1Sequence policies;
|
||||
|
||||
public static SigningCertificateV2 GetInstance(object o)
|
||||
{
|
||||
if (o == null || o is SigningCertificateV2)
|
||||
{
|
||||
return (SigningCertificateV2)o;
|
||||
}
|
||||
if (o is Asn1Sequence)
|
||||
{
|
||||
return new SigningCertificateV2((Asn1Sequence)o);
|
||||
}
|
||||
throw new ArgumentException("unknown object in 'SigningCertificateV2' factory : " + Platform.GetTypeName(o) + ".");
|
||||
}
|
||||
|
||||
private SigningCertificateV2(Asn1Sequence seq)
|
||||
{
|
||||
if (seq.Count < 1 || seq.Count > 2)
|
||||
{
|
||||
throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
|
||||
}
|
||||
certs = Asn1Sequence.GetInstance(seq[0].ToAsn1Object());
|
||||
if (seq.Count > 1)
|
||||
{
|
||||
policies = Asn1Sequence.GetInstance(seq[1].ToAsn1Object());
|
||||
}
|
||||
}
|
||||
|
||||
public SigningCertificateV2(EssCertIDv2 cert)
|
||||
{
|
||||
certs = new DerSequence(cert);
|
||||
}
|
||||
|
||||
public SigningCertificateV2(EssCertIDv2[] certs)
|
||||
{
|
||||
this.certs = new DerSequence(certs);
|
||||
}
|
||||
|
||||
public SigningCertificateV2(EssCertIDv2[] certs, PolicyInformation[] policies)
|
||||
{
|
||||
this.certs = new DerSequence(certs);
|
||||
if (policies != null)
|
||||
{
|
||||
this.policies = new DerSequence(policies);
|
||||
}
|
||||
}
|
||||
|
||||
public EssCertIDv2[] GetCerts()
|
||||
{
|
||||
EssCertIDv2[] array = new EssCertIDv2[certs.Count];
|
||||
for (int i = 0; i != certs.Count; i++)
|
||||
{
|
||||
array[i] = EssCertIDv2.GetInstance(certs[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public PolicyInformation[] GetPolicies()
|
||||
{
|
||||
if (policies == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
PolicyInformation[] array = new PolicyInformation[policies.Count];
|
||||
for (int i = 0; i != policies.Count; i++)
|
||||
{
|
||||
array[i] = PolicyInformation.GetInstance(policies[i]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(certs);
|
||||
if (policies != null)
|
||||
{
|
||||
asn1EncodableVector.Add(policies);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user