mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-25 15:59:36 +03:00
ssl_certs: Add dup_into
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
This commit is contained in:
parent
494db4cd51
commit
5a5670410b
@ -86,6 +86,18 @@ struct cert_chain {
|
||||
*/
|
||||
nserror cert_chain_alloc(size_t depth, struct cert_chain **chain_out);
|
||||
|
||||
/**
|
||||
* duplicate a certificate chain into an existing chain
|
||||
*
|
||||
* \param src The certificate chain to copy from
|
||||
* \param dst The chain to overwrite with a copy of src
|
||||
* \return NSERROR_OK on success or NSERROR_NOMEM on memory exhaustion
|
||||
*
|
||||
* NOTE: if this returns NSERROR_NOMEM then the destination chain will have
|
||||
* some amount of content and should be cleaned up with cert_chain_free.
|
||||
*/
|
||||
nserror cert_chain_dup_into(const struct cert_chain *src, struct cert_chain *dst);
|
||||
|
||||
/**
|
||||
* duplicate a certificate chain
|
||||
*
|
||||
|
@ -53,6 +53,43 @@ cert_chain_alloc(size_t depth, struct cert_chain **chain_out)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* duplicate certificate chain into existing chain
|
||||
*
|
||||
* exported interface documented in netsurf/ssl_certs.h
|
||||
*/
|
||||
nserror
|
||||
cert_chain_dup_into(const struct cert_chain *src, struct cert_chain *dst)
|
||||
{
|
||||
size_t depth;
|
||||
for (depth = 0; depth < dst->depth; depth++) {
|
||||
if (dst->certs[depth].der != NULL) {
|
||||
free(dst->certs[depth].der);
|
||||
dst->certs[depth].der = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
dst->depth = src->depth;
|
||||
|
||||
for (depth = 0; depth < src->depth; depth++) {
|
||||
dst->certs[depth].err = src->certs[depth].err;
|
||||
dst->certs[depth].der_length = src->certs[depth].der_length;
|
||||
if (src->certs[depth].der != NULL) {
|
||||
dst->certs[depth].der = malloc(src->certs[depth].der_length);
|
||||
if (dst->certs[depth].der == NULL) {
|
||||
return NSERROR_NOMEM;
|
||||
}
|
||||
memcpy(dst->certs[depth].der,
|
||||
src->certs[depth].der,
|
||||
src->certs[depth].der_length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* duplicate certificate chain
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user