blob: 6819e713df8415f227080a80f2c069fb9e67a1eb (
plain)
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
|
package model.csr;
import model.asn1.ASN1Object;
import model.asn1.Encodable;
import model.asn1.Tag;
import model.asn1.exceptions.ParseException;
import model.asn1.parsing.BytesReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
/**
* Represents a CSR Attributes list.
* <pre>
* Attributes { ATTRIBUTE:IOSet } ::= SET OF Attribute{{ IOSet }}
* </pre>
*/
public class Attributes extends ASN1Object {
private final Attribute[] array;
/**
* EFFECT: Initialize the list with the given tag, parentTag, and array. For tag and parentTag, consult
* {@link ASN1Object}.
*/
public Attributes(Tag tag, Tag parentTag, Attribute[] array) {
super(tag, parentTag);
this.array = array;
}
/**
* EFFECT: Parse the list from input DER bytes. For details on parsing, refer to {@link ASN1Object}.
* Throws {@link ParseException} for invalid input.
* MODIFIES: this, encoded
*/
public Attributes(BytesReader encoded, boolean hasParentTag) throws ParseException {
super(encoded, hasParentTag);
final List<Attribute> list = new ArrayList<>();
for (int i = 0; i < getLength();) {
int index = encoded.getIndex();
final Attribute attribute = new Attribute(encoded, false);
attribute.getTag().enforce(TAG_SEQUENCE);
list.add(attribute);
index = encoded.getIndex() - index;
i += index;
}
this.array = list.toArray(new Attribute[0]);
}
/**
* EFFECTS: Encode the SET OF into DER, keep order. Values will be encoded one-by-one.
*/
@Override
public Byte[] encodeValueDER() {
return Stream.of(array)
.map(Encodable::encodeDER)
.flatMap(Arrays::stream)
.toArray(Byte[]::new);
}
public Attribute[] getArray() {
return array;
}
}
|