2016-05-17 14:24:46 -04:00
|
|
|
/*
|
2020-11-26 14:18:57 +00:00
|
|
|
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 10:52:47 +00:00
|
|
|
*
|
2018-12-06 13:46:38 +01:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 14:24:46 -04:00
|
|
|
* 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 16:56:48 +02:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-23 22:13:45 +00:00
|
|
|
#include <openssl/objects.h>
|
|
|
|
#include <openssl/buffer.h>
|
2019-09-28 00:45:33 +02:00
|
|
|
#include "crypto/asn1.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 14:32:16 +01: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))
|
2017-10-17 23:04:09 +09: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) {
|
2020-11-04 12:23:19 +01:00
|
|
|
ERR_raise(ERR_LIB_OBJ, ERR_R_ASN1_LIB);
|
2017-10-17 23:04:09 +09:00
|
|
|
return NULL;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1998-12-21 10:52:47 +00:00
|
|
|
|
2016-05-18 14:32:16 +01: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 14:32:16 +01: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 14:32:16 +01:00
|
|
|
ASN1_OBJECT_free(r);
|
2020-11-04 12:23:19 +01:00
|
|
|
ERR_raise(ERR_LIB_OBJ, ERR_R_MALLOC_FAILURE);
|
2016-05-18 14:32:16 +01: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)
|
2017-10-17 23:04:09 +09:00
|
|
|
return ret;
|
|
|
|
return memcmp(a->data, b->data, a->length);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|