+SSLSetRecordContext (SSLContextRef ctx,
+ SSLRecordContextRef recCtx)
+{
+ if(ctx == NULL) {
+ return errSecParam;
+ }
+ if(sslIsSessionActive(ctx)) {
+ /* can't do this with an active session */
+ return errSecBadReq;
+ }
+ ctx->recCtx = recCtx;
+ return errSecSuccess;
+}
+
+/* Those two trampolines are used to make the connetion between
+ the record layer IO callbacks and the user provided IO callbacks.
+ Those are currently necessary because the record layer read/write callbacks
+ have different prototypes that the user callbacks advertised in the API.
+ They have different prototypes because the record layer callback have to build in kernelland.
+
+ This situation is not desirable. So we should figure out a way to get rid of them.
+ */
+static int IORead(SSLIOConnectionRef connection,
+ void *data,
+ size_t *dataLength)
+{
+ OSStatus rc;
+ SSLContextRef ctx = connection;
+
+
+ rc = ctx->ioCtx.read(ctx->ioCtx.ioRef, data, dataLength);
+
+ /* We may need to translate error codes at this layer */
+ if(rc==errSSLWouldBlock) {
+ rc=errSSLRecordWouldBlock;
+ }
+
+ return rc;
+}
+
+static int IOWrite(SSLIOConnectionRef connection,
+ const void *data,
+ size_t *dataLength)
+{
+ OSStatus rc;
+ SSLContextRef ctx = connection;
+
+ rc = ctx->ioCtx.write(ctx->ioCtx.ioRef, data, dataLength);
+
+ /* We may need to translate error codes at this layer */
+ if(rc==errSSLWouldBlock) {
+ rc=errSSLRecordWouldBlock;
+ }
+ return rc;
+}
+
+
+OSStatus
+SSLSetIOFuncs (SSLContextRef ctx,