2016-05-18 02:24:46 +08:00
|
|
|
/*
|
2017-09-29 05:27:04 +08:00
|
|
|
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2018-12-06 20:46:38 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:24:46 +08: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 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/objects.h>
|
|
|
|
#include <openssl/buffer.h>
|
2015-03-16 00:26:04 +08:00
|
|
|
#include "internal/asn1_int.h"
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-12-14 01:15:03 +08:00
|
|
|
ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ASN1_OBJECT *r;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (o == NULL)
|
2016-05-18 21:32:16 +08:00
|
|
|
return NULL;
|
|
|
|
/* If object isn't dynamic it's an internal OID which is never freed */
|
2015-01-22 11:40:55 +08:00
|
|
|
if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))
|
2017-10-17 22:04:09 +08:00
|
|
|
return (ASN1_OBJECT *)o;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
r = ASN1_OBJECT_new();
|
|
|
|
if (r == NULL) {
|
|
|
|
OBJerr(OBJ_F_OBJ_DUP, ERR_R_ASN1_LIB);
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2016-05-18 21:32:16 +08:00
|
|
|
/* Set dynamic flags so everything gets freed up on error */
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
r->flags = o->flags | (ASN1_OBJECT_FLAG_DYNAMIC |
|
|
|
|
ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
|
|
|
|
ASN1_OBJECT_FLAG_DYNAMIC_DATA);
|
2016-05-18 21:32:16 +08: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 11:40:55 +08:00
|
|
|
err:
|
2016-05-18 21:32:16 +08:00
|
|
|
ASN1_OBJECT_free(r);
|
2015-01-22 11:40:55 +08:00
|
|
|
OBJerr(OBJ_F_OBJ_DUP, ERR_R_MALLOC_FAILURE);
|
2016-05-18 21:32:16 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-12-14 01:15:03 +08:00
|
|
|
int OBJ_cmp(const ASN1_OBJECT *a, const ASN1_OBJECT *b)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
int ret;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
ret = (a->length - b->length);
|
|
|
|
if (ret)
|
2017-10-17 22:04:09 +08:00
|
|
|
return ret;
|
|
|
|
return memcmp(a->data, b->data, a->length);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|