blob: d49b1d9d29331a98f532f13d3c9968517a739360 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
using System;
using System.Collections;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Cms;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Cms
{
/**
* Default authenticated attributes generator.
*/
public class DefaultAuthenticatedAttributeTableGenerator
: CmsAttributeTableGenerator
{
private readonly IDictionary table;
/**
* Initialise to use all defaults
*/
public DefaultAuthenticatedAttributeTableGenerator()
{
table = 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 = 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 = 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);
}
}
}
|