-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move/group i2d_ASN1_OBJECT() and d2i_ASN1_OBJECT().
- Loading branch information
jsing
committed
Mar 20, 2022
1 parent
6ff827d
commit f6ff892
Showing
1 changed file
with
53 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* $OpenBSD: a_object.c,v 1.43 2022/03/19 17:49:32 jsing Exp $ */ | ||
/* $OpenBSD: a_object.c,v 1.44 2022/03/20 13:27:23 jsing Exp $ */ | ||
/* Copyright (C) 1995-1998 Eric Young ([email protected]) | ||
* All rights reserved. | ||
* | ||
|
@@ -123,28 +123,6 @@ ASN1_OBJECT_create(int nid, unsigned char *data, int len, | |
return (OBJ_dup(&o)); | ||
} | ||
|
||
int | ||
i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp) | ||
{ | ||
unsigned char *p; | ||
int objsize; | ||
|
||
if ((a == NULL) || (a->data == NULL)) | ||
return (0); | ||
|
||
objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT); | ||
if (pp == NULL) | ||
return objsize; | ||
|
||
p = *pp; | ||
ASN1_put_object(&p, 0, a->length, V_ASN1_OBJECT, V_ASN1_UNIVERSAL); | ||
memcpy(p, a->data, a->length); | ||
p += a->length; | ||
|
||
*pp = p; | ||
return (objsize); | ||
} | ||
|
||
static int | ||
oid_add_arc(CBB *cbb, uint64_t arc) | ||
{ | ||
|
@@ -541,36 +519,6 @@ i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *aobj) | |
return ret; | ||
} | ||
|
||
ASN1_OBJECT * | ||
d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long length) | ||
{ | ||
const unsigned char *p; | ||
long len; | ||
int tag, xclass; | ||
int inf, i; | ||
ASN1_OBJECT *ret = NULL; | ||
|
||
p = *pp; | ||
inf = ASN1_get_object(&p, &len, &tag, &xclass, length); | ||
if (inf & 0x80) { | ||
i = ASN1_R_BAD_OBJECT_HEADER; | ||
goto err; | ||
} | ||
|
||
if (tag != V_ASN1_OBJECT) { | ||
i = ASN1_R_EXPECTING_AN_OBJECT; | ||
goto err; | ||
} | ||
ret = c2i_ASN1_OBJECT(a, &p, len); | ||
if (ret) | ||
*pp = p; | ||
return ret; | ||
|
||
err: | ||
ASN1error(i); | ||
return (NULL); | ||
} | ||
|
||
ASN1_OBJECT * | ||
c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len) | ||
{ | ||
|
@@ -646,3 +594,55 @@ c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long len) | |
ASN1_OBJECT_free(ret); | ||
return (NULL); | ||
} | ||
|
||
int | ||
i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp) | ||
{ | ||
unsigned char *p; | ||
int objsize; | ||
|
||
if ((a == NULL) || (a->data == NULL)) | ||
return (0); | ||
|
||
objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT); | ||
if (pp == NULL) | ||
return objsize; | ||
|
||
p = *pp; | ||
ASN1_put_object(&p, 0, a->length, V_ASN1_OBJECT, V_ASN1_UNIVERSAL); | ||
memcpy(p, a->data, a->length); | ||
p += a->length; | ||
|
||
*pp = p; | ||
return (objsize); | ||
} | ||
|
||
ASN1_OBJECT * | ||
d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, long length) | ||
{ | ||
const unsigned char *p; | ||
long len; | ||
int tag, xclass; | ||
int inf, i; | ||
ASN1_OBJECT *ret = NULL; | ||
|
||
p = *pp; | ||
inf = ASN1_get_object(&p, &len, &tag, &xclass, length); | ||
if (inf & 0x80) { | ||
i = ASN1_R_BAD_OBJECT_HEADER; | ||
goto err; | ||
} | ||
|
||
if (tag != V_ASN1_OBJECT) { | ||
i = ASN1_R_EXPECTING_AN_OBJECT; | ||
goto err; | ||
} | ||
ret = c2i_ASN1_OBJECT(a, &p, len); | ||
if (ret) | ||
*pp = p; | ||
return ret; | ||
|
||
err: | ||
ASN1error(i); | ||
return (NULL); | ||
} |