init commit

This commit is contained in:
2025-10-09 09:57:24 +09:00
commit 4d551bd74f
6636 changed files with 1218703 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
using System;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1.Crmf;
public class AttributeTypeAndValue : Asn1Encodable
{
private readonly DerObjectIdentifier type;
private readonly Asn1Encodable value;
public virtual DerObjectIdentifier Type => type;
public virtual Asn1Encodable Value => value;
private AttributeTypeAndValue(Asn1Sequence seq)
{
type = (DerObjectIdentifier)seq[0];
value = seq[1];
}
public static AttributeTypeAndValue GetInstance(object obj)
{
if (obj is AttributeTypeAndValue)
{
return (AttributeTypeAndValue)obj;
}
if (obj is Asn1Sequence)
{
return new AttributeTypeAndValue((Asn1Sequence)obj);
}
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
}
public AttributeTypeAndValue(string oid, Asn1Encodable value)
: this(new DerObjectIdentifier(oid), value)
{
}
public AttributeTypeAndValue(DerObjectIdentifier type, Asn1Encodable value)
{
this.type = type;
this.value = value;
}
public override Asn1Object ToAsn1Object()
{
return new DerSequence(type, value);
}
}

View File

@@ -0,0 +1,45 @@
using System;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1.Crmf;
public class CertId : Asn1Encodable
{
private readonly GeneralName issuer;
private readonly DerInteger serialNumber;
public virtual GeneralName Issuer => issuer;
public virtual DerInteger SerialNumber => serialNumber;
private CertId(Asn1Sequence seq)
{
issuer = GeneralName.GetInstance(seq[0]);
serialNumber = DerInteger.GetInstance(seq[1]);
}
public static CertId GetInstance(object obj)
{
if (obj is CertId)
{
return (CertId)obj;
}
if (obj is Asn1Sequence)
{
return new CertId((Asn1Sequence)obj);
}
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
}
public static CertId GetInstance(Asn1TaggedObject obj, bool isExplicit)
{
return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
}
public override Asn1Object ToAsn1Object()
{
return new DerSequence(issuer, serialNumber);
}
}

View File

@@ -0,0 +1,47 @@
using System;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1.Crmf;
public class CertReqMessages : Asn1Encodable
{
private readonly Asn1Sequence content;
private CertReqMessages(Asn1Sequence seq)
{
content = seq;
}
public static CertReqMessages GetInstance(object obj)
{
if (obj is CertReqMessages)
{
return (CertReqMessages)obj;
}
if (obj is Asn1Sequence)
{
return new CertReqMessages((Asn1Sequence)obj);
}
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
}
public CertReqMessages(params CertReqMsg[] msgs)
{
content = new DerSequence(msgs);
}
public virtual CertReqMsg[] ToCertReqMsgArray()
{
CertReqMsg[] array = new CertReqMsg[content.Count];
for (int i = 0; i != array.Length; i++)
{
array[i] = CertReqMsg.GetInstance(content[i]);
}
return array;
}
public override Asn1Object ToAsn1Object()
{
return content;
}
}

View File

@@ -0,0 +1,86 @@
using System;
namespace Org.BouncyCastle.Asn1.Crmf;
public class CertReqMsg : Asn1Encodable
{
private readonly CertRequest certReq;
private readonly ProofOfPossession popo;
private readonly Asn1Sequence regInfo;
public virtual CertRequest CertReq => certReq;
public virtual ProofOfPossession Popo => popo;
private CertReqMsg(Asn1Sequence seq)
{
certReq = CertRequest.GetInstance(seq[0]);
for (int i = 1; i < seq.Count; i++)
{
object obj = seq[i];
if (obj is Asn1TaggedObject || obj is ProofOfPossession)
{
popo = ProofOfPossession.GetInstance(obj);
}
else
{
regInfo = Asn1Sequence.GetInstance(obj);
}
}
}
public static CertReqMsg GetInstance(object obj)
{
if (obj is CertReqMsg)
{
return (CertReqMsg)obj;
}
if (obj != null)
{
return new CertReqMsg(Asn1Sequence.GetInstance(obj));
}
return null;
}
public static CertReqMsg GetInstance(Asn1TaggedObject obj, bool isExplicit)
{
return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
}
public CertReqMsg(CertRequest certReq, ProofOfPossession popo, AttributeTypeAndValue[] regInfo)
{
if (certReq == null)
{
throw new ArgumentNullException("certReq");
}
this.certReq = certReq;
this.popo = popo;
if (regInfo != null)
{
this.regInfo = new DerSequence(regInfo);
}
}
public virtual AttributeTypeAndValue[] GetRegInfo()
{
if (regInfo == null)
{
return null;
}
AttributeTypeAndValue[] array = new AttributeTypeAndValue[regInfo.Count];
for (int i = 0; i != array.Length; i++)
{
array[i] = AttributeTypeAndValue.GetInstance(regInfo[i]);
}
return array;
}
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(certReq);
asn1EncodableVector.AddOptional(popo, regInfo);
return new DerSequence(asn1EncodableVector);
}
}

View File

@@ -0,0 +1,58 @@
namespace Org.BouncyCastle.Asn1.Crmf;
public class CertRequest : Asn1Encodable
{
private readonly DerInteger certReqId;
private readonly CertTemplate certTemplate;
private readonly Controls controls;
public virtual DerInteger CertReqID => certReqId;
public virtual CertTemplate CertTemplate => certTemplate;
public virtual Controls Controls => controls;
private CertRequest(Asn1Sequence seq)
{
certReqId = DerInteger.GetInstance(seq[0]);
certTemplate = CertTemplate.GetInstance(seq[1]);
if (seq.Count > 2)
{
controls = Controls.GetInstance(seq[2]);
}
}
public static CertRequest GetInstance(object obj)
{
if (obj is CertRequest)
{
return (CertRequest)obj;
}
if (obj != null)
{
return new CertRequest(Asn1Sequence.GetInstance(obj));
}
return null;
}
public CertRequest(int certReqId, CertTemplate certTemplate, Controls controls)
: this(new DerInteger(certReqId), certTemplate, controls)
{
}
public CertRequest(DerInteger certReqId, CertTemplate certTemplate, Controls controls)
{
this.certReqId = certReqId;
this.certTemplate = certTemplate;
this.controls = controls;
}
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(certReqId, certTemplate);
asn1EncodableVector.AddOptional(controls);
return new DerSequence(asn1EncodableVector);
}
}

View File

@@ -0,0 +1,110 @@
using System;
using Org.BouncyCastle.Asn1.X509;
namespace Org.BouncyCastle.Asn1.Crmf;
public class CertTemplate : Asn1Encodable
{
private readonly Asn1Sequence seq;
private readonly DerInteger version;
private readonly DerInteger serialNumber;
private readonly AlgorithmIdentifier signingAlg;
private readonly X509Name issuer;
private readonly OptionalValidity validity;
private readonly X509Name subject;
private readonly SubjectPublicKeyInfo publicKey;
private readonly DerBitString issuerUID;
private readonly DerBitString subjectUID;
private readonly X509Extensions extensions;
public virtual int Version => version.Value.IntValue;
public virtual DerInteger SerialNumber => serialNumber;
public virtual AlgorithmIdentifier SigningAlg => signingAlg;
public virtual X509Name Issuer => issuer;
public virtual OptionalValidity Validity => validity;
public virtual X509Name Subject => subject;
public virtual SubjectPublicKeyInfo PublicKey => publicKey;
public virtual DerBitString IssuerUID => issuerUID;
public virtual DerBitString SubjectUID => subjectUID;
public virtual X509Extensions Extensions => extensions;
private CertTemplate(Asn1Sequence seq)
{
this.seq = seq;
foreach (Asn1TaggedObject item in seq)
{
switch (item.TagNo)
{
case 0:
version = DerInteger.GetInstance(item, isExplicit: false);
break;
case 1:
serialNumber = DerInteger.GetInstance(item, isExplicit: false);
break;
case 2:
signingAlg = AlgorithmIdentifier.GetInstance(item, explicitly: false);
break;
case 3:
issuer = X509Name.GetInstance(item, explicitly: true);
break;
case 4:
validity = OptionalValidity.GetInstance(Asn1Sequence.GetInstance(item, explicitly: false));
break;
case 5:
subject = X509Name.GetInstance(item, explicitly: true);
break;
case 6:
publicKey = SubjectPublicKeyInfo.GetInstance(item, explicitly: false);
break;
case 7:
issuerUID = DerBitString.GetInstance(item, isExplicit: false);
break;
case 8:
subjectUID = DerBitString.GetInstance(item, isExplicit: false);
break;
case 9:
extensions = X509Extensions.GetInstance(item, explicitly: false);
break;
default:
throw new ArgumentException("unknown tag: " + item.TagNo, "seq");
}
}
}
public static CertTemplate GetInstance(object obj)
{
if (obj is CertTemplate)
{
return (CertTemplate)obj;
}
if (obj != null)
{
return new CertTemplate(Asn1Sequence.GetInstance(obj));
}
return null;
}
public override Asn1Object ToAsn1Object()
{
return seq;
}
}

View File

@@ -0,0 +1,110 @@
using Org.BouncyCastle.Asn1.X509;
namespace Org.BouncyCastle.Asn1.Crmf;
public class CertTemplateBuilder
{
private DerInteger version;
private DerInteger serialNumber;
private AlgorithmIdentifier signingAlg;
private X509Name issuer;
private OptionalValidity validity;
private X509Name subject;
private SubjectPublicKeyInfo publicKey;
private DerBitString issuerUID;
private DerBitString subjectUID;
private X509Extensions extensions;
public virtual CertTemplateBuilder SetVersion(int ver)
{
version = new DerInteger(ver);
return this;
}
public virtual CertTemplateBuilder SetSerialNumber(DerInteger ser)
{
serialNumber = ser;
return this;
}
public virtual CertTemplateBuilder SetSigningAlg(AlgorithmIdentifier aid)
{
signingAlg = aid;
return this;
}
public virtual CertTemplateBuilder SetIssuer(X509Name name)
{
issuer = name;
return this;
}
public virtual CertTemplateBuilder SetValidity(OptionalValidity v)
{
validity = v;
return this;
}
public virtual CertTemplateBuilder SetSubject(X509Name name)
{
subject = name;
return this;
}
public virtual CertTemplateBuilder SetPublicKey(SubjectPublicKeyInfo spki)
{
publicKey = spki;
return this;
}
public virtual CertTemplateBuilder SetIssuerUID(DerBitString uid)
{
issuerUID = uid;
return this;
}
public virtual CertTemplateBuilder SetSubjectUID(DerBitString uid)
{
subjectUID = uid;
return this;
}
public virtual CertTemplateBuilder SetExtensions(X509Extensions extens)
{
extensions = extens;
return this;
}
public virtual CertTemplate Build()
{
Asn1EncodableVector v = new Asn1EncodableVector();
AddOptional(v, 0, isExplicit: false, version);
AddOptional(v, 1, isExplicit: false, serialNumber);
AddOptional(v, 2, isExplicit: false, signingAlg);
AddOptional(v, 3, isExplicit: true, issuer);
AddOptional(v, 4, isExplicit: false, validity);
AddOptional(v, 5, isExplicit: true, subject);
AddOptional(v, 6, isExplicit: false, publicKey);
AddOptional(v, 7, isExplicit: false, issuerUID);
AddOptional(v, 8, isExplicit: false, subjectUID);
AddOptional(v, 9, isExplicit: false, extensions);
return CertTemplate.GetInstance(new DerSequence(v));
}
private void AddOptional(Asn1EncodableVector v, int tagNo, bool isExplicit, Asn1Encodable obj)
{
if (obj != null)
{
v.Add(new DerTaggedObject(isExplicit, tagNo, obj));
}
}
}

View File

@@ -0,0 +1,47 @@
using System;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1.Crmf;
public class Controls : Asn1Encodable
{
private readonly Asn1Sequence content;
private Controls(Asn1Sequence seq)
{
content = seq;
}
public static Controls GetInstance(object obj)
{
if (obj is Controls)
{
return (Controls)obj;
}
if (obj is Asn1Sequence)
{
return new Controls((Asn1Sequence)obj);
}
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
}
public Controls(params AttributeTypeAndValue[] atvs)
{
content = new DerSequence(atvs);
}
public virtual AttributeTypeAndValue[] ToAttributeTypeAndValueArray()
{
AttributeTypeAndValue[] array = new AttributeTypeAndValue[content.Count];
for (int i = 0; i != array.Length; i++)
{
array[i] = AttributeTypeAndValue.GetInstance(content[i]);
}
return array;
}
public override Asn1Object ToAsn1Object()
{
return content;
}
}

View File

@@ -0,0 +1,20 @@
namespace Org.BouncyCastle.Asn1.Crmf;
public abstract class CrmfObjectIdentifiers
{
public static readonly DerObjectIdentifier id_pkix = new DerObjectIdentifier("1.3.6.1.5.5.7");
public static readonly DerObjectIdentifier id_pkip = id_pkix.Branch("5");
public static readonly DerObjectIdentifier id_regCtrl = id_pkip.Branch("1");
public static readonly DerObjectIdentifier id_regCtrl_regToken = id_regCtrl.Branch("1");
public static readonly DerObjectIdentifier id_regCtrl_authenticator = id_regCtrl.Branch("2");
public static readonly DerObjectIdentifier id_regCtrl_pkiPublicationInfo = id_regCtrl.Branch("3");
public static readonly DerObjectIdentifier id_regCtrl_pkiArchiveOptions = id_regCtrl.Branch("4");
public static readonly DerObjectIdentifier id_ct_encKeyWithID = new DerObjectIdentifier("1.2.840.113549.1.9.16.1.21");
}

View File

@@ -0,0 +1,77 @@
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Asn1.X509;
namespace Org.BouncyCastle.Asn1.Crmf;
public class EncKeyWithID : Asn1Encodable
{
private readonly PrivateKeyInfo privKeyInfo;
private readonly Asn1Encodable identifier;
public virtual PrivateKeyInfo PrivateKey => privKeyInfo;
public virtual bool HasIdentifier => identifier != null;
public virtual bool IsIdentifierUtf8String => identifier is DerUtf8String;
public virtual Asn1Encodable Identifier => identifier;
public static EncKeyWithID GetInstance(object obj)
{
if (obj is EncKeyWithID)
{
return (EncKeyWithID)obj;
}
if (obj != null)
{
return new EncKeyWithID(Asn1Sequence.GetInstance(obj));
}
return null;
}
private EncKeyWithID(Asn1Sequence seq)
{
privKeyInfo = PrivateKeyInfo.GetInstance(seq[0]);
if (seq.Count > 1)
{
if (!(seq[1] is DerUtf8String))
{
identifier = GeneralName.GetInstance(seq[1]);
}
else
{
identifier = seq[1];
}
}
else
{
identifier = null;
}
}
public EncKeyWithID(PrivateKeyInfo privKeyInfo)
{
this.privKeyInfo = privKeyInfo;
identifier = null;
}
public EncKeyWithID(PrivateKeyInfo privKeyInfo, DerUtf8String str)
{
this.privKeyInfo = privKeyInfo;
identifier = str;
}
public EncKeyWithID(PrivateKeyInfo privKeyInfo, GeneralName generalName)
{
this.privKeyInfo = privKeyInfo;
identifier = generalName;
}
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(privKeyInfo);
asn1EncodableVector.AddOptional(identifier);
return new DerSequence(asn1EncodableVector);
}
}

View File

@@ -0,0 +1,60 @@
using Org.BouncyCastle.Asn1.Cms;
namespace Org.BouncyCastle.Asn1.Crmf;
public class EncryptedKey : Asn1Encodable, IAsn1Choice
{
private readonly EnvelopedData envelopedData;
private readonly EncryptedValue encryptedValue;
public virtual bool IsEncryptedValue => encryptedValue != null;
public virtual Asn1Encodable Value
{
get
{
if (encryptedValue != null)
{
return encryptedValue;
}
return envelopedData;
}
}
public static EncryptedKey GetInstance(object o)
{
if (o is EncryptedKey)
{
return (EncryptedKey)o;
}
if (o is Asn1TaggedObject)
{
return new EncryptedKey(EnvelopedData.GetInstance((Asn1TaggedObject)o, explicitly: false));
}
if (o is EncryptedValue)
{
return new EncryptedKey((EncryptedValue)o);
}
return new EncryptedKey(EncryptedValue.GetInstance(o));
}
public EncryptedKey(EnvelopedData envelopedData)
{
this.envelopedData = envelopedData;
}
public EncryptedKey(EncryptedValue encryptedValue)
{
this.encryptedValue = encryptedValue;
}
public override Asn1Object ToAsn1Object()
{
if (encryptedValue != null)
{
return encryptedValue.ToAsn1Object();
}
return new DerTaggedObject(explicitly: false, 0, envelopedData);
}
}

View File

@@ -0,0 +1,106 @@
using System;
using Org.BouncyCastle.Asn1.X509;
namespace Org.BouncyCastle.Asn1.Crmf;
public class EncryptedValue : Asn1Encodable
{
private readonly AlgorithmIdentifier intendedAlg;
private readonly AlgorithmIdentifier symmAlg;
private readonly DerBitString encSymmKey;
private readonly AlgorithmIdentifier keyAlg;
private readonly Asn1OctetString valueHint;
private readonly DerBitString encValue;
public virtual AlgorithmIdentifier IntendedAlg => intendedAlg;
public virtual AlgorithmIdentifier SymmAlg => symmAlg;
public virtual DerBitString EncSymmKey => encSymmKey;
public virtual AlgorithmIdentifier KeyAlg => keyAlg;
public virtual Asn1OctetString ValueHint => valueHint;
public virtual DerBitString EncValue => encValue;
private EncryptedValue(Asn1Sequence seq)
{
int i;
for (i = 0; seq[i] is Asn1TaggedObject; i++)
{
Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)seq[i];
switch (asn1TaggedObject.TagNo)
{
case 0:
intendedAlg = AlgorithmIdentifier.GetInstance(asn1TaggedObject, explicitly: false);
break;
case 1:
symmAlg = AlgorithmIdentifier.GetInstance(asn1TaggedObject, explicitly: false);
break;
case 2:
encSymmKey = DerBitString.GetInstance(asn1TaggedObject, isExplicit: false);
break;
case 3:
keyAlg = AlgorithmIdentifier.GetInstance(asn1TaggedObject, explicitly: false);
break;
case 4:
valueHint = Asn1OctetString.GetInstance(asn1TaggedObject, isExplicit: false);
break;
}
}
encValue = DerBitString.GetInstance(seq[i]);
}
public static EncryptedValue GetInstance(object obj)
{
if (obj is EncryptedValue)
{
return (EncryptedValue)obj;
}
if (obj != null)
{
return new EncryptedValue(Asn1Sequence.GetInstance(obj));
}
return null;
}
public EncryptedValue(AlgorithmIdentifier intendedAlg, AlgorithmIdentifier symmAlg, DerBitString encSymmKey, AlgorithmIdentifier keyAlg, Asn1OctetString valueHint, DerBitString encValue)
{
if (encValue == null)
{
throw new ArgumentNullException("encValue");
}
this.intendedAlg = intendedAlg;
this.symmAlg = symmAlg;
this.encSymmKey = encSymmKey;
this.keyAlg = keyAlg;
this.valueHint = valueHint;
this.encValue = encValue;
}
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
AddOptional(asn1EncodableVector, 0, intendedAlg);
AddOptional(asn1EncodableVector, 1, symmAlg);
AddOptional(asn1EncodableVector, 2, encSymmKey);
AddOptional(asn1EncodableVector, 3, keyAlg);
AddOptional(asn1EncodableVector, 4, valueHint);
asn1EncodableVector.Add(encValue);
return new DerSequence(asn1EncodableVector);
}
private void AddOptional(Asn1EncodableVector v, int tagNo, Asn1Encodable obj)
{
if (obj != null)
{
v.Add(new DerTaggedObject(explicitly: false, tagNo, obj));
}
}
}

View File

@@ -0,0 +1,58 @@
using Org.BouncyCastle.Asn1.X509;
namespace Org.BouncyCastle.Asn1.Crmf;
public class OptionalValidity : Asn1Encodable
{
private readonly Time notBefore;
private readonly Time notAfter;
public virtual Time NotBefore => notBefore;
public virtual Time NotAfter => notAfter;
private OptionalValidity(Asn1Sequence seq)
{
foreach (Asn1TaggedObject item in seq)
{
if (item.TagNo == 0)
{
notBefore = Time.GetInstance(item, explicitly: true);
}
else
{
notAfter = Time.GetInstance(item, explicitly: true);
}
}
}
public static OptionalValidity GetInstance(object obj)
{
if (obj == null || obj is OptionalValidity)
{
return (OptionalValidity)obj;
}
return new OptionalValidity(Asn1Sequence.GetInstance(obj));
}
public OptionalValidity(Time notBefore, Time notAfter)
{
this.notBefore = notBefore;
this.notAfter = notAfter;
}
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
if (notBefore != null)
{
asn1EncodableVector.Add(new DerTaggedObject(explicitly: true, 0, notBefore));
}
if (notAfter != null)
{
asn1EncodableVector.Add(new DerTaggedObject(explicitly: true, 1, notAfter));
}
return new DerSequence(asn1EncodableVector);
}
}

View File

@@ -0,0 +1,57 @@
using System;
using Org.BouncyCastle.Asn1.Cmp;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1.Crmf;
public class PKMacValue : Asn1Encodable
{
private readonly AlgorithmIdentifier algID;
private readonly DerBitString macValue;
public virtual AlgorithmIdentifier AlgID => algID;
public virtual DerBitString MacValue => macValue;
private PKMacValue(Asn1Sequence seq)
{
algID = AlgorithmIdentifier.GetInstance(seq[0]);
macValue = DerBitString.GetInstance(seq[1]);
}
public static PKMacValue GetInstance(object obj)
{
if (obj is PKMacValue)
{
return (PKMacValue)obj;
}
if (obj is Asn1Sequence)
{
return new PKMacValue((Asn1Sequence)obj);
}
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
}
public static PKMacValue GetInstance(Asn1TaggedObject obj, bool isExplicit)
{
return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
}
public PKMacValue(PbmParameter pbmParams, DerBitString macValue)
: this(new AlgorithmIdentifier(CmpObjectIdentifiers.passwordBasedMac, pbmParams), macValue)
{
}
public PKMacValue(AlgorithmIdentifier algID, DerBitString macValue)
{
this.algID = algID;
this.macValue = macValue;
}
public override Asn1Object ToAsn1Object()
{
return new DerSequence(algID, macValue);
}
}

View File

@@ -0,0 +1,92 @@
using System;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1.Crmf;
public class PkiArchiveOptions : Asn1Encodable, IAsn1Choice
{
public const int encryptedPrivKey = 0;
public const int keyGenParameters = 1;
public const int archiveRemGenPrivKey = 2;
private readonly Asn1Encodable value;
public virtual int Type
{
get
{
if (value is EncryptedKey)
{
return 0;
}
if (value is Asn1OctetString)
{
return 1;
}
return 2;
}
}
public virtual Asn1Encodable Value => value;
public static PkiArchiveOptions GetInstance(object obj)
{
if (obj is PkiArchiveOptions)
{
return (PkiArchiveOptions)obj;
}
if (obj is Asn1TaggedObject)
{
return new PkiArchiveOptions((Asn1TaggedObject)obj);
}
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
}
private PkiArchiveOptions(Asn1TaggedObject tagged)
{
switch (tagged.TagNo)
{
case 0:
value = EncryptedKey.GetInstance(tagged.GetObject());
break;
case 1:
value = Asn1OctetString.GetInstance(tagged, isExplicit: false);
break;
case 2:
value = DerBoolean.GetInstance(tagged, isExplicit: false);
break;
default:
throw new ArgumentException("unknown tag number: " + tagged.TagNo, "tagged");
}
}
public PkiArchiveOptions(EncryptedKey encKey)
{
value = encKey;
}
public PkiArchiveOptions(Asn1OctetString keyGenParameters)
{
value = keyGenParameters;
}
public PkiArchiveOptions(bool archiveRemGenPrivKey)
{
value = DerBoolean.GetInstance(archiveRemGenPrivKey);
}
public override Asn1Object ToAsn1Object()
{
if (value is EncryptedKey)
{
return new DerTaggedObject(explicitly: true, 0, value);
}
if (value is Asn1OctetString)
{
return new DerTaggedObject(explicitly: false, 1, value);
}
return new DerTaggedObject(explicitly: false, 2, value);
}
}

View File

@@ -0,0 +1,51 @@
using System;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1.Crmf;
public class PkiPublicationInfo : Asn1Encodable
{
private readonly DerInteger action;
private readonly Asn1Sequence pubInfos;
public virtual DerInteger Action => action;
private PkiPublicationInfo(Asn1Sequence seq)
{
action = DerInteger.GetInstance(seq[0]);
pubInfos = Asn1Sequence.GetInstance(seq[1]);
}
public static PkiPublicationInfo GetInstance(object obj)
{
if (obj is PkiPublicationInfo)
{
return (PkiPublicationInfo)obj;
}
if (obj is Asn1Sequence)
{
return new PkiPublicationInfo((Asn1Sequence)obj);
}
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
}
public virtual SinglePubInfo[] GetPubInfos()
{
if (pubInfos == null)
{
return null;
}
SinglePubInfo[] array = new SinglePubInfo[pubInfos.Count];
for (int i = 0; i != array.Length; i++)
{
array[i] = SinglePubInfo.GetInstance(pubInfos[i]);
}
return array;
}
public override Asn1Object ToAsn1Object()
{
return new DerSequence(action, pubInfos);
}
}

View File

@@ -0,0 +1,66 @@
using System;
using Org.BouncyCastle.Asn1.Cms;
namespace Org.BouncyCastle.Asn1.Crmf;
public class PopoPrivKey : Asn1Encodable, IAsn1Choice
{
public const int thisMessage = 0;
public const int subsequentMessage = 1;
public const int dhMAC = 2;
public const int agreeMAC = 3;
public const int encryptedKey = 4;
private readonly int tagNo;
private readonly Asn1Encodable obj;
public virtual int Type => tagNo;
public virtual Asn1Encodable Value => obj;
private PopoPrivKey(Asn1TaggedObject obj)
{
tagNo = obj.TagNo;
switch (tagNo)
{
case 0:
this.obj = DerBitString.GetInstance(obj, isExplicit: false);
break;
case 1:
this.obj = SubsequentMessage.ValueOf(DerInteger.GetInstance(obj, isExplicit: false).Value.IntValue);
break;
case 2:
this.obj = DerBitString.GetInstance(obj, isExplicit: false);
break;
case 3:
this.obj = PKMacValue.GetInstance(obj, isExplicit: false);
break;
case 4:
this.obj = EnvelopedData.GetInstance(obj, explicitly: false);
break;
default:
throw new ArgumentException("unknown tag in PopoPrivKey", "obj");
}
}
public static PopoPrivKey GetInstance(Asn1TaggedObject tagged, bool isExplicit)
{
return new PopoPrivKey(Asn1TaggedObject.GetInstance(tagged.GetObject()));
}
public PopoPrivKey(SubsequentMessage msg)
{
tagNo = 1;
obj = msg;
}
public override Asn1Object ToAsn1Object()
{
return new DerTaggedObject(explicitly: false, tagNo, obj);
}
}

View File

@@ -0,0 +1,73 @@
using System;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1.Crmf;
public class PopoSigningKey : Asn1Encodable
{
private readonly PopoSigningKeyInput poposkInput;
private readonly AlgorithmIdentifier algorithmIdentifier;
private readonly DerBitString signature;
public virtual PopoSigningKeyInput PoposkInput => poposkInput;
public virtual AlgorithmIdentifier AlgorithmIdentifier => algorithmIdentifier;
public virtual DerBitString Signature => signature;
private PopoSigningKey(Asn1Sequence seq)
{
int index = 0;
if (seq[index] is Asn1TaggedObject)
{
Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)seq[index++];
if (asn1TaggedObject.TagNo != 0)
{
throw new ArgumentException("Unknown PopoSigningKeyInput tag: " + asn1TaggedObject.TagNo, "seq");
}
poposkInput = PopoSigningKeyInput.GetInstance(asn1TaggedObject.GetObject());
}
algorithmIdentifier = AlgorithmIdentifier.GetInstance(seq[index++]);
signature = DerBitString.GetInstance(seq[index]);
}
public static PopoSigningKey GetInstance(object obj)
{
if (obj is PopoSigningKey)
{
return (PopoSigningKey)obj;
}
if (obj is Asn1Sequence)
{
return new PopoSigningKey((Asn1Sequence)obj);
}
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
}
public static PopoSigningKey GetInstance(Asn1TaggedObject obj, bool isExplicit)
{
return GetInstance(Asn1Sequence.GetInstance(obj, isExplicit));
}
public PopoSigningKey(PopoSigningKeyInput poposkIn, AlgorithmIdentifier aid, DerBitString signature)
{
poposkInput = poposkIn;
algorithmIdentifier = aid;
this.signature = signature;
}
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
if (poposkInput != null)
{
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 0, poposkInput));
}
asn1EncodableVector.Add(algorithmIdentifier);
asn1EncodableVector.Add(signature);
return new DerSequence(asn1EncodableVector);
}
}

View File

@@ -0,0 +1,79 @@
using System;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1.Crmf;
public class PopoSigningKeyInput : Asn1Encodable
{
private readonly GeneralName sender;
private readonly PKMacValue publicKeyMac;
private readonly SubjectPublicKeyInfo publicKey;
public virtual GeneralName Sender => sender;
public virtual PKMacValue PublicKeyMac => publicKeyMac;
public virtual SubjectPublicKeyInfo PublicKey => publicKey;
private PopoSigningKeyInput(Asn1Sequence seq)
{
Asn1Encodable asn1Encodable = seq[0];
if (asn1Encodable is Asn1TaggedObject)
{
Asn1TaggedObject asn1TaggedObject = (Asn1TaggedObject)asn1Encodable;
if (asn1TaggedObject.TagNo != 0)
{
throw new ArgumentException("Unknown authInfo tag: " + asn1TaggedObject.TagNo, "seq");
}
sender = GeneralName.GetInstance(asn1TaggedObject.GetObject());
}
else
{
publicKeyMac = PKMacValue.GetInstance(asn1Encodable);
}
publicKey = SubjectPublicKeyInfo.GetInstance(seq[1]);
}
public static PopoSigningKeyInput GetInstance(object obj)
{
if (obj is PopoSigningKeyInput)
{
return (PopoSigningKeyInput)obj;
}
if (obj is Asn1Sequence)
{
return new PopoSigningKeyInput((Asn1Sequence)obj);
}
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
}
public PopoSigningKeyInput(GeneralName sender, SubjectPublicKeyInfo spki)
{
this.sender = sender;
publicKey = spki;
}
public PopoSigningKeyInput(PKMacValue pkmac, SubjectPublicKeyInfo spki)
{
publicKeyMac = pkmac;
publicKey = spki;
}
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector();
if (sender != null)
{
asn1EncodableVector.Add(new DerTaggedObject(explicitly: false, 0, sender));
}
else
{
asn1EncodableVector.Add(publicKeyMac);
}
asn1EncodableVector.Add(publicKey);
return new DerSequence(asn1EncodableVector);
}
}

View File

@@ -0,0 +1,79 @@
using System;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1.Crmf;
public class ProofOfPossession : Asn1Encodable, IAsn1Choice
{
public const int TYPE_RA_VERIFIED = 0;
public const int TYPE_SIGNING_KEY = 1;
public const int TYPE_KEY_ENCIPHERMENT = 2;
public const int TYPE_KEY_AGREEMENT = 3;
private readonly int tagNo;
private readonly Asn1Encodable obj;
public virtual int Type => tagNo;
public virtual Asn1Encodable Object => obj;
private ProofOfPossession(Asn1TaggedObject tagged)
{
tagNo = tagged.TagNo;
switch (tagNo)
{
case 0:
obj = DerNull.Instance;
break;
case 1:
obj = PopoSigningKey.GetInstance(tagged, isExplicit: false);
break;
case 2:
case 3:
obj = PopoPrivKey.GetInstance(tagged, isExplicit: false);
break;
default:
throw new ArgumentException("unknown tag: " + tagNo, "tagged");
}
}
public static ProofOfPossession GetInstance(object obj)
{
if (obj is ProofOfPossession)
{
return (ProofOfPossession)obj;
}
if (obj is Asn1TaggedObject)
{
return new ProofOfPossession((Asn1TaggedObject)obj);
}
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
}
public ProofOfPossession()
{
tagNo = 0;
obj = DerNull.Instance;
}
public ProofOfPossession(PopoSigningKey Poposk)
{
tagNo = 1;
obj = Poposk;
}
public ProofOfPossession(int type, PopoPrivKey privkey)
{
tagNo = type;
obj = privkey;
}
public override Asn1Object ToAsn1Object()
{
return new DerTaggedObject(explicitly: false, tagNo, obj);
}
}

View File

@@ -0,0 +1,43 @@
using System;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1.Crmf;
public class SinglePubInfo : Asn1Encodable
{
private readonly DerInteger pubMethod;
private readonly GeneralName pubLocation;
public virtual GeneralName PubLocation => pubLocation;
private SinglePubInfo(Asn1Sequence seq)
{
pubMethod = DerInteger.GetInstance(seq[0]);
if (seq.Count == 2)
{
pubLocation = GeneralName.GetInstance(seq[1]);
}
}
public static SinglePubInfo GetInstance(object obj)
{
if (obj is SinglePubInfo)
{
return (SinglePubInfo)obj;
}
if (obj is Asn1Sequence)
{
return new SinglePubInfo((Asn1Sequence)obj);
}
throw new ArgumentException("Invalid object: " + Platform.GetTypeName(obj), "obj");
}
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(pubMethod);
asn1EncodableVector.AddOptional(pubLocation);
return new DerSequence(asn1EncodableVector);
}
}

View File

@@ -0,0 +1,25 @@
using System;
namespace Org.BouncyCastle.Asn1.Crmf;
public class SubsequentMessage : DerInteger
{
public static readonly SubsequentMessage encrCert = new SubsequentMessage(0);
public static readonly SubsequentMessage challengeResp = new SubsequentMessage(1);
private SubsequentMessage(int value)
: base(value)
{
}
public static SubsequentMessage ValueOf(int value)
{
return value switch
{
0 => encrCert,
1 => challengeResp,
_ => throw new ArgumentException("unknown value: " + value, "value"),
};
}
}