培训考核三期,新版培训,网页版培训登录器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.9 KiB

#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Cms
{
/**
* Default authenticated attributes generator.
*/
public class DefaultAuthenticatedAttributeTableGenerator
: CmsAttributeTableGenerator
{
private readonly IDictionary table;
/**
* Initialise to use all defaults
*/
public DefaultAuthenticatedAttributeTableGenerator()
{
table = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
}
/**
* Initialise with some extra attributes or overrides.
*
* @param attributeTable initial attribute table to use.
*/
public DefaultAuthenticatedAttributeTableGenerator(
AttributeTable attributeTable)
{
if (attributeTable != null)
{
table = attributeTable.ToDictionary();
}
else
{
table = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable();
}
}
/**
* Create a standard attribute table from the passed in parameters - this will
* normally include contentType and messageDigest. If the constructor
* using an AttributeTable was used, entries in it for contentType and
* messageDigest will override the generated ones.
*
* @param parameters source parameters for table generation.
*
* @return a filled in IDictionary of attributes.
*/
protected virtual IDictionary CreateStandardAttributeTable(
IDictionary parameters)
{
IDictionary std = BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.CreateHashtable(table);
if (!std.Contains(CmsAttributes.ContentType))
{
DerObjectIdentifier contentType = (DerObjectIdentifier)
parameters[CmsAttributeTableParameter.ContentType];
Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(CmsAttributes.ContentType,
new DerSet(contentType));
std[attr.AttrType] = attr;
}
if (!std.Contains(CmsAttributes.MessageDigest))
{
byte[] messageDigest = (byte[])parameters[CmsAttributeTableParameter.Digest];
Asn1.Cms.Attribute attr = new Asn1.Cms.Attribute(CmsAttributes.MessageDigest,
new DerSet(new DerOctetString(messageDigest)));
std[attr.AttrType] = attr;
}
return std;
}
/**
* @param parameters source parameters
* @return the populated attribute table
*/
public virtual AttributeTable GetAttributes(
IDictionary parameters)
{
IDictionary table = CreateStandardAttributeTable(parameters);
return new AttributeTable(table);
}
}
}
#pragma warning restore
#endif