2016-05-17 18:24:46 +00:00
|
|
|
/*
|
2017-09-28 21:27:04 +00:00
|
|
|
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 10:52:47 +00:00
|
|
|
*
|
2016-05-17 18:24:46 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1998-12-21 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-23 22:13:45 +00:00
|
|
|
#include <openssl/objects.h>
|
|
|
|
#include <openssl/buffer.h>
|
2015-03-15 16:26:04 +00:00
|
|
|
#include "internal/asn1_int.h"
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2000-12-13 17:15:03 +00:00
|
|
|
ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
ASN1_OBJECT *r;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (o == NULL)
|
2016-05-18 13:32:16 +00:00
|
|
|
return NULL;
|
|
|
|
/* If object isn't dynamic it's an internal OID which is never freed */
|
2015-01-22 03:40:55 +00:00
|
|
|
if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))
|
2016-05-18 13:32:16 +00:00
|
|
|
return ((ASN1_OBJECT *)o);
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
r = ASN1_OBJECT_new();
|
|
|
|
if (r == NULL) {
|
|
|
|
OBJerr(OBJ_F_OBJ_DUP, ERR_R_ASN1_LIB);
|
|
|
|
return (NULL);
|
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2016-05-18 13:32:16 +00:00
|
|
|
/* Set dynamic flags so everything gets freed up on error */
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
r->flags = o->flags | (ASN1_OBJECT_FLAG_DYNAMIC |
|
|
|
|
ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
|
|
|
|
ASN1_OBJECT_FLAG_DYNAMIC_DATA);
|
2016-05-18 13:32:16 +00:00
|
|
|
|
|
|
|
if (o->length > 0 && (r->data = OPENSSL_memdup(o->data, o->length)) == NULL)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
r->length = o->length;
|
|
|
|
r->nid = o->nid;
|
|
|
|
|
|
|
|
if (o->ln != NULL && (r->ln = OPENSSL_strdup(o->ln)) == NULL)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (o->sn != NULL && (r->sn = OPENSSL_strdup(o->sn)) == NULL)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return r;
|
2015-01-22 03:40:55 +00:00
|
|
|
err:
|
2016-05-18 13:32:16 +00:00
|
|
|
ASN1_OBJECT_free(r);
|
2015-01-22 03:40:55 +00:00
|
|
|
OBJerr(OBJ_F_OBJ_DUP, ERR_R_MALLOC_FAILURE);
|
2016-05-18 13:32:16 +00:00
|
|
|
return NULL;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2000-12-13 17:15:03 +00:00
|
|
|
int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
int ret;
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
ret = (a->length - b->length);
|
|
|
|
if (ret)
|
|
|
|
return (ret);
|
|
|
|
return (memcmp(a->data, b->data, a->length));
|
|
|
|
}
|