
#use wml::openssl-macros area=docs page=d2i_SSL_SESSION

<title>Documents, d2i_SSL_SESSION(3)</title>

<h1>d2i_SSL_SESSION(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#NOTES">NOTES</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
d2i_SSL_SESSION, i2d_SSL_SESSION - convert SSL_SESSION object from/to ASN1
representation

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/ssl.h&gt;
</PRE>
<PRE> SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length);
 int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>d2i_SSL_SESSION()</CODE> transforms the external ASN1 representation
of an SSL/TLS session, stored as binary data at location <STRONG>pp</STRONG> with length <STRONG>length</STRONG>, into an SSL_SESSION object.

</P>
<P>
<CODE>i2d_SSL_SESSION()</CODE> transforms the SSL_SESSION object <STRONG>in</STRONG> into the ASN1 representation and stores it into the memory location pointed
to by <STRONG>pp</STRONG>. The length of the resulting ASN1 representation is returned. If <STRONG>pp</STRONG> is the NULL pointer, only the length is calculated and returned.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
The SSL_SESSION object is built from several <CODE>malloc()ed</CODE> parts,
it can therefore not be moved, copied or stored directly. In order to store
session data on disk or into a database, it must be transformed into a
binary ASN1 representation.

</P>
<P>
When using <CODE>d2i_SSL_SESSION(),</CODE> the SSL_SESSION object is
automatically allocated. The reference count is 1, so that the session must
be explicitly removed using <A HREF="../ssl/SSL_SESSION_free.html#">SSL_SESSION_free(3)</A>, unless the SSL_SESSION object is completely taken over, when being called
inside the <CODE>get_session_cb()</CODE> (see
<A HREF="../ssl/SSL_CTX_sess_set_get_cb.html#">SSL_CTX_sess_set_get_cb(3)</A>).

</P>
<P>
SSL_SESSION objects keep internal link information about the session cache
list, when being inserted into one SSL_CTX object's session cache. One
SSL_SESSION object, regardless of its reference count, must therefore only
be used with one SSL_CTX object (and the SSL objects created from this
SSL_CTX object).

</P>
<P>
When using <CODE>i2d_SSL_SESSION(),</CODE> the memory location pointed to
by <STRONG>pp</STRONG> must be large enough to hold the binary representation of the session.
There is no known limit on the size of the created ASN1 representation, so
the necessary amount of space should be obtained by first calling
<CODE>i2d_SSL_SESSION()</CODE> with
<STRONG>pp=NULL</STRONG>, and obtain the size needed, then allocate the memory and call
<CODE>i2d_SSL_SESSION()</CODE> again.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>d2i_SSL_SESSION()</CODE> returns a pointer to the newly allocated
SSL_SESSION object. In case of failure the NULL-pointer is returned and the
error message can be retrieved from the error stack.

</P>
<P>
<CODE>i2d_SSL_SESSION()</CODE> returns the size of the ASN1 representation
in bytes. When the session is not valid, <STRONG>0</STRONG> is returned and no operation is performed.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../ssl/ssl.html#">ssl(3)</A>, <A HREF="../ssl/SSL_SESSION_free.html#">SSL_SESSION_free(3)</A>,
<A HREF="../ssl/SSL_CTX_sess_set_get_cb.html#">SSL_CTX_sess_set_get_cb(3)</A>



</P>
:}


