diff options
author | Yuuta Liang <yuutaw@students.cs.ubc.ca> | 2023-10-12 12:10:33 +0800 |
---|---|---|
committer | Yuuta Liang <yuutaw@students.cs.ubc.ca> | 2023-10-12 12:10:33 +0800 |
commit | d342a45d98c4795b3a3fe1aaef5236ad4a782b55 (patch) | |
tree | f4ebc0ad962b138d9371413fcc71c97a559df506 /src/main/model/pki/crl/CertificateList.java | |
parent | e60c9c76243cfe0a408af98dc60bedb973e815db (diff) | |
download | jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.tar jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.tar.gz jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.tar.bz2 jca-d342a45d98c4795b3a3fe1aaef5236ad4a782b55.zip |
Implement data structures from X.680, X.501, X.509, and PKCS#10, with X.690 encoding / decoding support
The implementation took four days, and it is still a little bit rough. Updated version should arrive soon.
Signed-off-by: Yuuta Liang <yuutaw@students.cs.ubc.ca>
Diffstat (limited to 'src/main/model/pki/crl/CertificateList.java')
-rw-r--r-- | src/main/model/pki/crl/CertificateList.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/main/model/pki/crl/CertificateList.java b/src/main/model/pki/crl/CertificateList.java new file mode 100644 index 0000000..5142101 --- /dev/null +++ b/src/main/model/pki/crl/CertificateList.java @@ -0,0 +1,76 @@ +package model.pki.crl; + +import model.asn1.ASN1Object; +import model.asn1.BitString; +import model.asn1.Tag; +import model.asn1.exceptions.ParseException; +import model.asn1.parsing.BytesReader; +import model.pki.AlgorithmIdentifier; +import model.pki.cert.TbsCertificate; + +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>. + */ + private final CertificateListContent crl; + + /** + * The algorithm used for <pre>signature</pre>. + */ + private final AlgorithmIdentifier signatureAlgorithm; + + /** + * The signature. + */ + 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; + } +} |