diff --git a/src/test/scala/tlschannel/helpers/NullSslSession.java b/src/test/scala/tlschannel/helpers/NullSslSession.java new file mode 100644 index 00000000..abc74bb5 --- /dev/null +++ b/src/test/scala/tlschannel/helpers/NullSslSession.java @@ -0,0 +1,116 @@ +package tlschannel.helpers; + +import java.security.Principal; +import java.security.cert.Certificate; +import javax.net.ssl.SSLSession; +import javax.net.ssl.SSLSessionContext; +import javax.security.cert.X509Certificate; + +public class NullSslSession implements SSLSession { + + private final int bufferSize; + + public NullSslSession(int bufferSize) { + this.bufferSize = bufferSize; + } + + @Override + public byte[] getId() { + return new byte[0]; + } + + @Override + public SSLSessionContext getSessionContext() { + return null; + } + + @Override + public long getCreationTime() { + return System.currentTimeMillis(); + } + + @Override + public long getLastAccessedTime() { + return System.currentTimeMillis(); + } + + @Override + public void invalidate() {} + + @Override + public boolean isValid() { + return false; + } + + @Override + public void putValue(String name, Object value) {} + + @Override + public Object getValue(String name) { + return null; + } + + @Override + public void removeValue(String name) {} + + @Override + public String[] getValueNames() { + return new String[0]; + } + + @Override + public Certificate[] getPeerCertificates() { + return new Certificate[0]; + } + + @Override + public Certificate[] getLocalCertificates() { + return new Certificate[0]; + } + + @Override + public Principal getPeerPrincipal() { + return null; + } + + @Override + public Principal getLocalPrincipal() { + return null; + } + + @Override + public String getCipherSuite() { + return null; + } + + @Override + public String getProtocol() { + return ""; + } + + @Override + public String getPeerHost() { + return null; + } + + @Override + public int getPeerPort() { + return 0; + } + + @Override + public int getPacketBufferSize() { + return 0; + } + + @Override + public int getApplicationBufferSize() { + return bufferSize; + } + + @Override + @SuppressWarnings("removal") + public X509Certificate[] getPeerCertificateChain() { + return new X509Certificate[0]; + } +} diff --git a/src/test/scala/tlschannel/helpers/NullSslSession.scala b/src/test/scala/tlschannel/helpers/NullSslSession.scala deleted file mode 100644 index 5f690e23..00000000 --- a/src/test/scala/tlschannel/helpers/NullSslSession.scala +++ /dev/null @@ -1,34 +0,0 @@ -package tlschannel.helpers - -import javax.net.ssl.SSLSession - -class NullSslSession(bufferSize: Int) extends SSLSession { - - def getApplicationBufferSize() = bufferSize - def getCipherSuite() = null - def getCreationTime() = System.currentTimeMillis() - def getId() = Array() - def getLastAccessedTime() = System.currentTimeMillis() - def getLocalCertificates() = Array() - def getLocalPrincipal() = null - def getPacketBufferSize() = bufferSize - - /** getPeerCertificateChain is a default method since Java 15, so we have to override to make the compiler happy (and - * still supply an implementation for earlier versions). - */ - override def getPeerCertificateChain() = Array() - - def getPeerCertificates() = Array() - def getPeerHost() = null - def getPeerPort() = 0 - def getPeerPrincipal() = null - def getProtocol() = "" - def getSessionContext() = null - def getValue(s: String) = null - def getValueNames() = Array() - def invalidate() = {} - def isValid() = true - def putValue(k: String, v: Any) = {} - def removeValue(k: String) = {} - -}