diff options
author | Sergio Giro <sgiro@google.com> | 2016-01-27 20:40:41 +0000 |
---|---|---|
committer | Sergio Giro <sgiro@google.com> | 2016-01-28 15:30:59 +0000 |
commit | 80261dd2d1824bb3862e90e77a5412d56ad88b1f (patch) | |
tree | d89e670054247d0a050ac1b0d9a7918cbe3498d6 /bcprov/src/main/java/org/bouncycastle/crypto/tls/CertificateStatusRequest.java | |
parent | 9be78fe4c709f1e585b5ed7e99b21084045b7fba (diff) | |
download | android_external_bouncycastle-80261dd2d1824bb3862e90e77a5412d56ad88b1f.tar.gz android_external_bouncycastle-80261dd2d1824bb3862e90e77a5412d56ad88b1f.tar.bz2 android_external_bouncycastle-80261dd2d1824bb3862e90e77a5412d56ad88b1f.zip |
bouncycastle: Android tree with upstream code for version 1.50
Android tree as of c0d8909a6c6a4ac075a9dee7ac1fe6baff34acc0
Change-Id: I8d381554d6edec32aae8ff5bab5d5314f0954440
Diffstat (limited to 'bcprov/src/main/java/org/bouncycastle/crypto/tls/CertificateStatusRequest.java')
-rw-r--r-- | bcprov/src/main/java/org/bouncycastle/crypto/tls/CertificateStatusRequest.java | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/bcprov/src/main/java/org/bouncycastle/crypto/tls/CertificateStatusRequest.java b/bcprov/src/main/java/org/bouncycastle/crypto/tls/CertificateStatusRequest.java new file mode 100644 index 0000000..b947c48 --- /dev/null +++ b/bcprov/src/main/java/org/bouncycastle/crypto/tls/CertificateStatusRequest.java @@ -0,0 +1,98 @@ +package org.bouncycastle.crypto.tls; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class CertificateStatusRequest +{ + protected short statusType; + protected Object request; + + public CertificateStatusRequest(short statusType, Object request) + { + if (!isCorrectType(statusType, request)) + { + throw new IllegalArgumentException("'request' is not an instance of the correct type"); + } + + this.statusType = statusType; + this.request = request; + } + + public short getStatusType() + { + return statusType; + } + + public Object getRequest() + { + return request; + } + + public OCSPStatusRequest getOCSPStatusRequest() + { + if (!isCorrectType(CertificateStatusType.ocsp, request)) + { + throw new IllegalStateException("'request' is not an OCSPStatusRequest"); + } + return (OCSPStatusRequest)request; + } + + /** + * Encode this {@link CertificateStatusRequest} to an {@link OutputStream}. + * + * @param output + * the {@link OutputStream} to encode to. + * @throws IOException + */ + public void encode(OutputStream output) throws IOException + { + TlsUtils.writeUint8(statusType, output); + + switch (statusType) + { + case CertificateStatusType.ocsp: + ((OCSPStatusRequest) request).encode(output); + break; + default: + throw new TlsFatalAlert(AlertDescription.internal_error); + } + } + + /** + * Parse a {@link CertificateStatusRequest} from an {@link InputStream}. + * + * @param input + * the {@link InputStream} to parse from. + * @return a {@link CertificateStatusRequest} object. + * @throws IOException + */ + public static CertificateStatusRequest parse(InputStream input) throws IOException + { + short status_type = TlsUtils.readUint8(input); + Object result; + + switch (status_type) + { + case CertificateStatusType.ocsp: + result = OCSPStatusRequest.parse(input); + break; + default: + throw new TlsFatalAlert(AlertDescription.decode_error); + } + + return new CertificateStatusRequest(status_type, result); + } + + protected static boolean isCorrectType(short statusType, Object request) + { + switch (statusType) + { + case CertificateStatusType.ocsp: + return request instanceof OCSPStatusRequest; + default: + throw new IllegalArgumentException("'statusType' is an unsupported value"); + } + } +} |