| 
									
										
										
										
											2016-05-18 02:24:46 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2020-11-26 22:18:57 +08:00
										 |  |  |  * Copyright 1995-2020 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>
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:33 +08:00
										 |  |  | #include "crypto/asn1.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) | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     ASN1_OBJECT *r; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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 */ | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-04-18 05:25:43 +08:00
										 |  |  |     r = ASN1_OBJECT_new(); | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  |     if (r == NULL) { | 
					
						
							| 
									
										
										
										
											2020-11-04 19:23:19 +08:00
										 |  |  |         ERR_raise(ERR_LIB_OBJ, ERR_R_ASN1_LIB); | 
					
						
							| 
									
										
										
										
											2017-10-17 22:04:09 +08:00
										 |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  |     r->flags = o->flags | (ASN1_OBJECT_FLAG_DYNAMIC | | 
					
						
							| 
									
										
										
										
											1998-12-21 19:00:56 +08:00
										 |  |  |                            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; | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  |  err: | 
					
						
							| 
									
										
										
										
											2016-05-18 21:32:16 +08:00
										 |  |  |     ASN1_OBJECT_free(r); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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); | 
					
						
							| 
									
										
										
										
											1998-12-21 18:52:47 +08:00
										 |  |  | } |