Path: blob/main/contrib/bearssl/src/x509/x509_knownkey.c
39507 views
/*1* Copyright (c) 2016 Thomas Pornin <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining4* a copy of this software and associated documentation files (the5* "Software"), to deal in the Software without restriction, including6* without limitation the rights to use, copy, modify, merge, publish,7* distribute, sublicense, and/or sell copies of the Software, and to8* permit persons to whom the Software is furnished to do so, subject to9* the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*/2324#include "inner.h"2526/* see bearssl_x509.h */27void28br_x509_knownkey_init_rsa(br_x509_knownkey_context *ctx,29const br_rsa_public_key *pk, unsigned usages)30{31ctx->vtable = &br_x509_knownkey_vtable;32ctx->pkey.key_type = BR_KEYTYPE_RSA;33ctx->pkey.key.rsa = *pk;34ctx->usages = usages;35}3637/* see bearssl_x509.h */38void39br_x509_knownkey_init_ec(br_x509_knownkey_context *ctx,40const br_ec_public_key *pk, unsigned usages)41{42ctx->vtable = &br_x509_knownkey_vtable;43ctx->pkey.key_type = BR_KEYTYPE_EC;44ctx->pkey.key.ec = *pk;45ctx->usages = usages;46}4748static void49kk_start_chain(const br_x509_class **ctx, const char *server_name)50{51(void)ctx;52(void)server_name;53}5455static void56kk_start_cert(const br_x509_class **ctx, uint32_t length)57{58(void)ctx;59(void)length;60}6162static void63kk_append(const br_x509_class **ctx, const unsigned char *buf, size_t len)64{65(void)ctx;66(void)buf;67(void)len;68}6970static void71kk_end_cert(const br_x509_class **ctx)72{73(void)ctx;74}7576static unsigned77kk_end_chain(const br_x509_class **ctx)78{79(void)ctx;80return 0;81}8283static const br_x509_pkey *84kk_get_pkey(const br_x509_class *const *ctx, unsigned *usages)85{86const br_x509_knownkey_context *xc;8788xc = (const br_x509_knownkey_context *)ctx;89if (usages != NULL) {90*usages = xc->usages;91}92return &xc->pkey;93}9495/* see bearssl_x509.h */96const br_x509_class br_x509_knownkey_vtable = {97sizeof(br_x509_knownkey_context),98kk_start_chain,99kk_start_cert,100kk_append,101kk_end_cert,102kk_end_chain,103kk_get_pkey104};105106107