diff options
author | Peter <peter@cryptic.(none)> | 2013-06-21 11:30:03 +0400 |
---|---|---|
committer | Peter <peter@cryptic.(none)> | 2013-06-21 11:30:03 +0400 |
commit | f3a4aa206e47a47a394b80c87d133cd4bf34ad13 (patch) | |
tree | cb8896862293c1c593382bbd356bf7aa3d5efac7 /core/src/main/java/org/bouncycastle/crypto/tls/CertificateStatus.java | |
parent | 9884183732cbf26fc7565e12a5be789129ed6849 (diff) |
Fix line endings
Diffstat (limited to 'core/src/main/java/org/bouncycastle/crypto/tls/CertificateStatus.java')
-rw-r--r-- | core/src/main/java/org/bouncycastle/crypto/tls/CertificateStatus.java | 210 |
1 files changed, 105 insertions, 105 deletions
diff --git a/core/src/main/java/org/bouncycastle/crypto/tls/CertificateStatus.java b/core/src/main/java/org/bouncycastle/crypto/tls/CertificateStatus.java index 59b757b6..c0ac8c7d 100644 --- a/core/src/main/java/org/bouncycastle/crypto/tls/CertificateStatus.java +++ b/core/src/main/java/org/bouncycastle/crypto/tls/CertificateStatus.java @@ -1,105 +1,105 @@ -package org.bouncycastle.crypto.tls;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.bouncycastle.asn1.ASN1Encoding;
-import org.bouncycastle.asn1.ocsp.OCSPResponse;
-
-public class CertificateStatus
-{
- protected short statusType;
- protected Object response;
-
- public CertificateStatus(short statusType, Object response)
- {
- if (!isCorrectType(statusType, response))
- {
- throw new IllegalArgumentException("'response' is not an instance of the correct type");
- }
-
- this.statusType = statusType;
- this.response = response;
- }
-
- public short getStatusType()
- {
- return statusType;
- }
-
- public Object getResponse()
- {
- return response;
- }
-
- public OCSPResponse getOCSPResponse()
- {
- if (!isCorrectType(CertificateStatusType.ocsp, response))
- {
- throw new IllegalStateException("'response' is not an OCSPResponse");
- }
- return (OCSPResponse)response;
- }
-
- /**
- * Encode this {@link CertificateStatus} 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:
- byte[] derEncoding = ((OCSPResponse) response).getEncoded(ASN1Encoding.DER);
- TlsUtils.writeOpaque24(derEncoding, output);
- break;
- default:
- throw new TlsFatalAlert(AlertDescription.internal_error);
- }
- }
-
- /**
- * Parse a {@link CertificateStatus} from an {@link InputStream}.
- *
- * @param input
- * the {@link InputStream} to parse from.
- * @return a {@link CertificateStatus} object.
- * @throws IOException
- */
- public static CertificateStatus parse(InputStream input) throws IOException
- {
- short status_type = TlsUtils.readUint8(input);
- Object response;
-
- switch (status_type)
- {
- case CertificateStatusType.ocsp:
- {
- byte[] derEncoding = TlsUtils.readOpaque24(input);
- response = OCSPResponse.getInstance(TlsUtils.readASN1Object(derEncoding));
- break;
- }
- default:
- throw new TlsFatalAlert(AlertDescription.decode_error);
- }
-
- return new CertificateStatus(status_type, response);
- }
-
- protected static boolean isCorrectType(short statusType, Object response)
- {
- switch (statusType)
- {
- case CertificateStatusType.ocsp:
- return response instanceof OCSPResponse;
- default:
- throw new IllegalArgumentException("'statusType' is an unsupported value");
- }
- }
-}
+package org.bouncycastle.crypto.tls; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.bouncycastle.asn1.ASN1Encoding; +import org.bouncycastle.asn1.ocsp.OCSPResponse; + +public class CertificateStatus +{ + protected short statusType; + protected Object response; + + public CertificateStatus(short statusType, Object response) + { + if (!isCorrectType(statusType, response)) + { + throw new IllegalArgumentException("'response' is not an instance of the correct type"); + } + + this.statusType = statusType; + this.response = response; + } + + public short getStatusType() + { + return statusType; + } + + public Object getResponse() + { + return response; + } + + public OCSPResponse getOCSPResponse() + { + if (!isCorrectType(CertificateStatusType.ocsp, response)) + { + throw new IllegalStateException("'response' is not an OCSPResponse"); + } + return (OCSPResponse)response; + } + + /** + * Encode this {@link CertificateStatus} 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: + byte[] derEncoding = ((OCSPResponse) response).getEncoded(ASN1Encoding.DER); + TlsUtils.writeOpaque24(derEncoding, output); + break; + default: + throw new TlsFatalAlert(AlertDescription.internal_error); + } + } + + /** + * Parse a {@link CertificateStatus} from an {@link InputStream}. + * + * @param input + * the {@link InputStream} to parse from. + * @return a {@link CertificateStatus} object. + * @throws IOException + */ + public static CertificateStatus parse(InputStream input) throws IOException + { + short status_type = TlsUtils.readUint8(input); + Object response; + + switch (status_type) + { + case CertificateStatusType.ocsp: + { + byte[] derEncoding = TlsUtils.readOpaque24(input); + response = OCSPResponse.getInstance(TlsUtils.readASN1Object(derEncoding)); + break; + } + default: + throw new TlsFatalAlert(AlertDescription.decode_error); + } + + return new CertificateStatus(status_type, response); + } + + protected static boolean isCorrectType(short statusType, Object response) + { + switch (statusType) + { + case CertificateStatusType.ocsp: + return response instanceof OCSPResponse; + default: + throw new IllegalArgumentException("'statusType' is an unsupported value"); + } + } +} |