|
Packit Service |
084de1 |
/*
|
|
Packit Service |
084de1 |
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
|
Packit Service |
084de1 |
*
|
|
Packit Service |
084de1 |
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
Packit Service |
084de1 |
* this file except in compliance with the License. You can obtain a copy
|
|
Packit Service |
084de1 |
* in the file LICENSE in the source distribution or at
|
|
Packit Service |
084de1 |
* https://www.openssl.org/source/license.html
|
|
Packit Service |
084de1 |
*/
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
#include <stdio.h>
|
|
Packit Service |
084de1 |
#include "internal/cryptlib.h"
|
|
Packit Service |
084de1 |
#include <openssl/objects.h>
|
|
Packit Service |
084de1 |
#include <openssl/buffer.h>
|
|
Packit Service |
084de1 |
#include "crypto/asn1.h"
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
ASN1_OBJECT *r;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (o == NULL)
|
|
Packit Service |
084de1 |
return NULL;
|
|
Packit Service |
084de1 |
/* If object isn't dynamic it's an internal OID which is never freed */
|
|
Packit Service |
084de1 |
if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))
|
|
Packit Service |
084de1 |
return (ASN1_OBJECT *)o;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
r = ASN1_OBJECT_new();
|
|
Packit Service |
084de1 |
if (r == NULL) {
|
|
Packit Service |
084de1 |
OBJerr(OBJ_F_OBJ_DUP, ERR_R_ASN1_LIB);
|
|
Packit Service |
084de1 |
return NULL;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
/* Set dynamic flags so everything gets freed up on error */
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
r->flags = o->flags | (ASN1_OBJECT_FLAG_DYNAMIC |
|
|
Packit Service |
084de1 |
ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
|
|
Packit Service |
084de1 |
ASN1_OBJECT_FLAG_DYNAMIC_DATA);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (o->length > 0 && (r->data = OPENSSL_memdup(o->data, o->length)) == NULL)
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
r->length = o->length;
|
|
Packit Service |
084de1 |
r->nid = o->nid;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (o->ln != NULL && (r->ln = OPENSSL_strdup(o->ln)) == NULL)
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
if (o->sn != NULL && (r->sn = OPENSSL_strdup(o->sn)) == NULL)
|
|
Packit Service |
084de1 |
goto err;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
return r;
|
|
Packit Service |
084de1 |
err:
|
|
Packit Service |
084de1 |
ASN1_OBJECT_free(r);
|
|
Packit Service |
084de1 |
OBJerr(OBJ_F_OBJ_DUP, ERR_R_MALLOC_FAILURE);
|
|
Packit Service |
084de1 |
return NULL;
|
|
Packit Service |
084de1 |
}
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b)
|
|
Packit Service |
084de1 |
{
|
|
Packit Service |
084de1 |
int ret;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
ret = (a->length - b->length);
|
|
Packit Service |
084de1 |
if (ret)
|
|
Packit Service |
084de1 |
return ret;
|
|
Packit Service |
084de1 |
return memcmp(a->data, b->data, a->length);
|
|
Packit Service |
084de1 |
}
|