/* * ____ _________ __ _ * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____ * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/ * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__ * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/ * /____/ * * SharkSSL Embedded SSL/TLS Stack **************************************************************************** * PROGRAM MODULE * Memory BIO example. * * $Id: SharkSslOsslBioExample.c 6928 2026-11-25 23:04:29Z wini $ * * COPYRIGHT: Real Time Logic LLC, 2026 * * This software is copyrighted by and is the sole property of Real * Time Logic LLC. All rights, title, ownership, or other interests in * the software remain the property of Real Time Logic LLC. This * software may only be used in accordance with the terms and * conditions stipulated in the corresponding license agreement under * which the software has been supplied. Any unauthorized use, * duplication, transmission, distribution, or disclosure of this * software is expressly forbidden. * * This Copyright notice may not be removed or modified without prior * written consent of Real Time Logic LLC. * * Real Time Logic LLC. reserves the right to modify this software * without notice. * * http://www.realtimelogic.com * http://www.sharkssl.com **************************************************************************** * */ /* [bio-example] */ #include "SharkSslOsslExample.h" #include #include #include int main(void) { const char message[] = "Hello from a memory BIO"; char buffer[sizeof(message)]; size_t written = 0, received = 0; /* The writable BIO owns its storage. No TLS engine or socket is needed. */ BIO* bio = BIO_new(BIO_s_mem()); int result = 1; /* Transfer message bytes only; leave room for a local display terminator. */ if (!bio || !BIO_write_ex(bio, message, sizeof(message) - 1, &written) || written != sizeof(message) - 1 || !BIO_read_ex(bio, buffer, sizeof(buffer) - 1, &received) || received != written || memcmp(buffer, message, received) != 0) { SharkSslOsslExample_error("Memory BIO round trip"); } else { buffer[received] = '\0'; puts(buffer); result = 0; } /* Safe after partial setup too: BIO_free accepts NULL. */ BIO_free(bio); return result; } /* [bio-example] */