aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/pki/crl/CertificateList.java
blob: 8f4b98b7dab68582d4bb097e71a7af47fc1c2804 (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
66
67
68
69
70
71
72
73
74
75
76
77
package model.pki.crl;

import annotations.Assoc;
import model.asn1.ASN1Object;
import model.asn1.BitString;
import model.asn1.Tag;
import model.pki.AlgorithmIdentifier;

import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Stream;

/**
 * Represents a signed X.509 CRL.
 * <pre>
 *      CertificateList ::= SIGNED{CertificateListContent}
 * </pre>
 */
public class CertificateList extends ASN1Object {
    /**
     * All info of that CRL, excluding the signature.
     * It will be signed, and the signature is in <pre>signature</pre>.
     */
    @Assoc(partOf = true)
    private final CertificateListContent crl;

    /**
     * The algorithm used for <pre>signature</pre>.
     */
    @Assoc(partOf = true)
    private final AlgorithmIdentifier signatureAlgorithm;

    /**
     * The signature.
     */
    @Assoc(partOf = true)
    private final BitString signature;

    /**
     * EFFECTS: Initialize the object with the given tag and parentTag, and list, signatureAlgorithm, and signature.
     * REQUIRES: The algorithm must match the signature. The fields must have correct tags as described in the class
     * specification (SEQUENCE, SEQUENCE, BIT STRING).
     */
    public CertificateList(Tag tag, Tag parentTag,
                           final CertificateListContent crl,
                           final AlgorithmIdentifier signatureAlgorithm,
                           final BitString signature) {
        super(tag, parentTag);
        this.crl = crl;
        this.signatureAlgorithm = signatureAlgorithm;
        this.signature = signature;
    }

    /**
     * EFFECT: Encode that sequence into an ordered array of bytes, following the class specification.
     */
    @Override
    public Byte[] encodeValueDER() {
        return Stream.of(Arrays.asList(crl.encodeDER()),
                        Arrays.asList(signatureAlgorithm.encodeDER()),
                        Arrays.asList(signature.encodeDER()))
                .flatMap(Collection::stream)
                .toArray(Byte[]::new);
    }

    public CertificateListContent getCrl() {
        return crl;
    }

    public AlgorithmIdentifier getSignatureAlgorithm() {
        return signatureAlgorithm;
    }

    public BitString getSignature() {
        return signature;
    }
}