File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -826,6 +826,36 @@ class Session:
826826 _session : Any
827827
828828
829+ def d2i_SSL_SESSION (data : bytes ) -> Session :
830+ p = _ffi .new ("unsigned char[]" , data )
831+ pp = _ffi .new ("unsigned char **" )
832+ pp [0 ] = p
833+ length = _ffi .cast ("long" , len (data ))
834+
835+ session = _lib .d2i_SSL_SESSION (_ffi .NULL , pp , length )
836+ if session == _ffi .NULL :
837+ raise RuntimeError ("d2i_SSL_SESSION failed" )
838+
839+ pysession = Session .__new__ (Session )
840+ pysession ._session = _ffi .gc (session , _lib .SSL_SESSION_free )
841+ return pysession
842+
843+ def i2d_SSL_SESSION (session : Session ) -> bytes :
844+
845+ length = _lib .i2d_SSL_SESSION (session ._session , _ffi .NULL )
846+ if length == 0 :
847+ raise RuntimeError ("i2d_SSL_SESSION failed to get length" )
848+
849+ pp = _ffi .new ("unsigned char **" )
850+ p = _ffi .new ("unsigned char[]" , length )
851+ pp [0 ] = p
852+
853+ length = _lib .i2d_SSL_SESSION (session ._session , pp )
854+ if length == 0 :
855+ raise RuntimeError ("i2d_SSL_SESSION failed to produce DER" )
856+
857+ return _ffi .buffer (p , length )[:]
858+
829859class Context :
830860 """
831861 :class:`OpenSSL.SSL.Context` instances define the parameters for setting
You can’t perform that action at this time.
0 commit comments