init commit
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
using Org.BouncyCastle.Asn1.Pkcs;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Smime;
|
||||
|
||||
public abstract class SmimeAttributes
|
||||
{
|
||||
public static readonly DerObjectIdentifier SmimeCapabilities = PkcsObjectIdentifiers.Pkcs9AtSmimeCapabilities;
|
||||
|
||||
public static readonly DerObjectIdentifier EncrypKeyPref = PkcsObjectIdentifiers.IdAAEncrypKeyPref;
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Org.BouncyCastle.Asn1.Nist;
|
||||
using Org.BouncyCastle.Asn1.Pkcs;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
using Org.BouncyCastle.Utilities;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Smime;
|
||||
|
||||
public class SmimeCapabilities : Asn1Encodable
|
||||
{
|
||||
public static readonly DerObjectIdentifier PreferSignedData = PkcsObjectIdentifiers.PreferSignedData;
|
||||
|
||||
public static readonly DerObjectIdentifier CannotDecryptAny = PkcsObjectIdentifiers.CannotDecryptAny;
|
||||
|
||||
public static readonly DerObjectIdentifier SmimeCapabilitesVersions = PkcsObjectIdentifiers.SmimeCapabilitiesVersions;
|
||||
|
||||
public static readonly DerObjectIdentifier Aes256Cbc = NistObjectIdentifiers.IdAes256Cbc;
|
||||
|
||||
public static readonly DerObjectIdentifier Aes192Cbc = NistObjectIdentifiers.IdAes192Cbc;
|
||||
|
||||
public static readonly DerObjectIdentifier Aes128Cbc = NistObjectIdentifiers.IdAes128Cbc;
|
||||
|
||||
public static readonly DerObjectIdentifier IdeaCbc = new DerObjectIdentifier("1.3.6.1.4.1.188.7.1.1.2");
|
||||
|
||||
public static readonly DerObjectIdentifier Cast5Cbc = new DerObjectIdentifier("1.2.840.113533.7.66.10");
|
||||
|
||||
public static readonly DerObjectIdentifier DesCbc = new DerObjectIdentifier("1.3.14.3.2.7");
|
||||
|
||||
public static readonly DerObjectIdentifier DesEde3Cbc = PkcsObjectIdentifiers.DesEde3Cbc;
|
||||
|
||||
public static readonly DerObjectIdentifier RC2Cbc = PkcsObjectIdentifiers.RC2Cbc;
|
||||
|
||||
private Asn1Sequence capabilities;
|
||||
|
||||
public static SmimeCapabilities GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is SmimeCapabilities)
|
||||
{
|
||||
return (SmimeCapabilities)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new SmimeCapabilities((Asn1Sequence)obj);
|
||||
}
|
||||
if (obj is AttributeX509)
|
||||
{
|
||||
return new SmimeCapabilities((Asn1Sequence)((AttributeX509)obj).AttrValues[0]);
|
||||
}
|
||||
throw new ArgumentException("unknown object in factory: " + Platform.GetTypeName(obj), "obj");
|
||||
}
|
||||
|
||||
public SmimeCapabilities(Asn1Sequence seq)
|
||||
{
|
||||
capabilities = seq;
|
||||
}
|
||||
|
||||
[Obsolete("Use 'GetCapabilitiesForOid' instead")]
|
||||
public ArrayList GetCapabilities(DerObjectIdentifier capability)
|
||||
{
|
||||
ArrayList arrayList = new ArrayList();
|
||||
DoGetCapabilitiesForOid(capability, arrayList);
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
public IList GetCapabilitiesForOid(DerObjectIdentifier capability)
|
||||
{
|
||||
IList list = Platform.CreateArrayList();
|
||||
DoGetCapabilitiesForOid(capability, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void DoGetCapabilitiesForOid(DerObjectIdentifier capability, IList list)
|
||||
{
|
||||
if (capability == null)
|
||||
{
|
||||
foreach (object capability2 in capabilities)
|
||||
{
|
||||
SmimeCapability instance = SmimeCapability.GetInstance(capability2);
|
||||
list.Add(instance);
|
||||
}
|
||||
return;
|
||||
}
|
||||
foreach (object capability3 in capabilities)
|
||||
{
|
||||
SmimeCapability instance2 = SmimeCapability.GetInstance(capability3);
|
||||
if (capability.Equals(instance2.CapabilityID))
|
||||
{
|
||||
list.Add(instance2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
return capabilities;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Smime;
|
||||
|
||||
public class SmimeCapabilitiesAttribute : AttributeX509
|
||||
{
|
||||
public SmimeCapabilitiesAttribute(SmimeCapabilityVector capabilities)
|
||||
: base(SmimeAttributes.SmimeCapabilities, new DerSet(new DerSequence(capabilities.ToAsn1EncodableVector())))
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using Org.BouncyCastle.Asn1.Pkcs;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Smime;
|
||||
|
||||
public class SmimeCapability : Asn1Encodable
|
||||
{
|
||||
public static readonly DerObjectIdentifier PreferSignedData = PkcsObjectIdentifiers.PreferSignedData;
|
||||
|
||||
public static readonly DerObjectIdentifier CannotDecryptAny = PkcsObjectIdentifiers.CannotDecryptAny;
|
||||
|
||||
public static readonly DerObjectIdentifier SmimeCapabilitiesVersions = PkcsObjectIdentifiers.SmimeCapabilitiesVersions;
|
||||
|
||||
public static readonly DerObjectIdentifier DesCbc = new DerObjectIdentifier("1.3.14.3.2.7");
|
||||
|
||||
public static readonly DerObjectIdentifier DesEde3Cbc = PkcsObjectIdentifiers.DesEde3Cbc;
|
||||
|
||||
public static readonly DerObjectIdentifier RC2Cbc = PkcsObjectIdentifiers.RC2Cbc;
|
||||
|
||||
private DerObjectIdentifier capabilityID;
|
||||
|
||||
private Asn1Object parameters;
|
||||
|
||||
public DerObjectIdentifier CapabilityID => capabilityID;
|
||||
|
||||
public Asn1Object Parameters => parameters;
|
||||
|
||||
public SmimeCapability(Asn1Sequence seq)
|
||||
{
|
||||
capabilityID = (DerObjectIdentifier)seq[0].ToAsn1Object();
|
||||
if (seq.Count > 1)
|
||||
{
|
||||
parameters = seq[1].ToAsn1Object();
|
||||
}
|
||||
}
|
||||
|
||||
public SmimeCapability(DerObjectIdentifier capabilityID, Asn1Encodable parameters)
|
||||
{
|
||||
if (capabilityID == null)
|
||||
{
|
||||
throw new ArgumentNullException("capabilityID");
|
||||
}
|
||||
this.capabilityID = capabilityID;
|
||||
if (parameters != null)
|
||||
{
|
||||
this.parameters = parameters.ToAsn1Object();
|
||||
}
|
||||
}
|
||||
|
||||
public static SmimeCapability GetInstance(object obj)
|
||||
{
|
||||
if (obj == null || obj is SmimeCapability)
|
||||
{
|
||||
return (SmimeCapability)obj;
|
||||
}
|
||||
if (obj is Asn1Sequence)
|
||||
{
|
||||
return new SmimeCapability((Asn1Sequence)obj);
|
||||
}
|
||||
throw new ArgumentException("Invalid SmimeCapability");
|
||||
}
|
||||
|
||||
public override Asn1Object ToAsn1Object()
|
||||
{
|
||||
Asn1EncodableVector asn1EncodableVector = new Asn1EncodableVector(capabilityID);
|
||||
if (parameters != null)
|
||||
{
|
||||
asn1EncodableVector.Add(parameters);
|
||||
}
|
||||
return new DerSequence(asn1EncodableVector);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace Org.BouncyCastle.Asn1.Smime;
|
||||
|
||||
public class SmimeCapabilityVector
|
||||
{
|
||||
private readonly Asn1EncodableVector capabilities = new Asn1EncodableVector();
|
||||
|
||||
public void AddCapability(DerObjectIdentifier capability)
|
||||
{
|
||||
capabilities.Add(new DerSequence(capability));
|
||||
}
|
||||
|
||||
public void AddCapability(DerObjectIdentifier capability, int value)
|
||||
{
|
||||
capabilities.Add(new DerSequence(capability, new DerInteger(value)));
|
||||
}
|
||||
|
||||
public void AddCapability(DerObjectIdentifier capability, Asn1Encodable parameters)
|
||||
{
|
||||
capabilities.Add(new DerSequence(capability, parameters));
|
||||
}
|
||||
|
||||
public Asn1EncodableVector ToAsn1EncodableVector()
|
||||
{
|
||||
return capabilities;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Org.BouncyCastle.Asn1.Cms;
|
||||
using Org.BouncyCastle.Asn1.X509;
|
||||
|
||||
namespace Org.BouncyCastle.Asn1.Smime;
|
||||
|
||||
public class SmimeEncryptionKeyPreferenceAttribute : AttributeX509
|
||||
{
|
||||
public SmimeEncryptionKeyPreferenceAttribute(IssuerAndSerialNumber issAndSer)
|
||||
: base(SmimeAttributes.EncrypKeyPref, new DerSet(new DerTaggedObject(explicitly: false, 0, issAndSer)))
|
||||
{
|
||||
}
|
||||
|
||||
public SmimeEncryptionKeyPreferenceAttribute(RecipientKeyIdentifier rKeyID)
|
||||
: base(SmimeAttributes.EncrypKeyPref, new DerSet(new DerTaggedObject(explicitly: false, 1, rKeyID)))
|
||||
{
|
||||
}
|
||||
|
||||
public SmimeEncryptionKeyPreferenceAttribute(Asn1OctetString sKeyID)
|
||||
: base(SmimeAttributes.EncrypKeyPref, new DerSet(new DerTaggedObject(explicitly: false, 2, sKeyID)))
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user