nl.topicus.jdbc.shaded.io.netty.handler.ssl.OpenSslCertificateException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spanner-jdbc Show documentation
Show all versions of spanner-jdbc Show documentation
JDBC Driver for Google Cloud Spanner
/*
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in nl.topicus.jdbc.shaded.com.liance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.nl.topicus.jdbc.shaded.org.licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package nl.topicus.jdbc.shaded.io.nl.topicus.jdbc.shaded.net.y.handler.ssl;
import nl.topicus.jdbc.shaded.io.nl.topicus.jdbc.shaded.net.y.internal.tcnative.CertificateVerifier;
import java.security.cert.CertificateException;
/**
* A special {@link CertificateException} which allows to specify which error code is included in the
* SSL Record. This only work when {@link SslProvider#OPENSSL} or {@link SslProvider#OPENSSL_REFCNT} is used.
*/
public final class OpenSslCertificateException extends CertificateException {
private static final long serialVersionUID = 5542675253797129798L;
private final int errorCode;
/**
* Construct a new exception with the
* error code.
*/
public OpenSslCertificateException(int errorCode) {
this((String) null, errorCode);
}
/**
* Construct a new exception with the msg and
* error code .
*/
public OpenSslCertificateException(String msg, int errorCode) {
super(msg);
this.errorCode = checkErrorCode(errorCode);
}
/**
* Construct a new exception with the msg, cause and
* error code .
*/
public OpenSslCertificateException(String message, Throwable cause, int errorCode) {
super(message, cause);
this.errorCode = checkErrorCode(errorCode);
}
/**
* Construct a new exception with the cause and
* error code .
*/
public OpenSslCertificateException(Throwable cause, int errorCode) {
this(null, cause, errorCode);
}
/**
* Return the error code to use.
*/
public int errorCode() {
return errorCode;
}
private static int checkErrorCode(int errorCode) {
if (!CertificateVerifier.isValid(errorCode)) {
throw new IllegalArgumentException("errorCode '" + errorCode +
"' invalid, see https://www.openssl.nl.topicus.jdbc.shaded.org.docs/man1.0.2/apps/verify.html.");
}
return errorCode;
}
}