New function ASN1_STRING_copy() to copy to an already

alloacted ASN1_STRING structure.
This commit is contained in:
Dr. Stephen Henson 2007-04-14 17:53:55 +00:00
parent be3b365a34
commit 18f547734e
2 changed files with 20 additions and 8 deletions

View File

@ -765,6 +765,7 @@ DECLARE_ASN1_SET_OF(ASN1_OBJECT)
ASN1_STRING * ASN1_STRING_new(void); ASN1_STRING * ASN1_STRING_new(void);
void ASN1_STRING_free(ASN1_STRING *a); void ASN1_STRING_free(ASN1_STRING *a);
int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str);
ASN1_STRING * ASN1_STRING_dup(const ASN1_STRING *a); ASN1_STRING * ASN1_STRING_dup(const ASN1_STRING *a);
ASN1_STRING * ASN1_STRING_type_new(int type ); ASN1_STRING * ASN1_STRING_type_new(int type );
int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b); int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b);

View File

@ -340,20 +340,31 @@ int asn1_GetSequence(ASN1_const_CTX *c, long *length)
return(1); return(1);
} }
int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str)
{
if (str == NULL)
return 0;
dst->type = str->type;
if (!ASN1_STRING_set(dst,str->data,str->length))
return 0;
dst->flags = str->flags;
return 1;
}
ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str) ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str)
{ {
ASN1_STRING *ret; ASN1_STRING *ret;
if (!str)
if (str == NULL) return(NULL); return NULL;
if ((ret=ASN1_STRING_type_new(str->type)) == NULL) ret=ASN1_STRING_new();
return(NULL); if (!ret)
if (!ASN1_STRING_set(ret,str->data,str->length)) return NULL;
if (!ASN1_STRING_copy(ret,str))
{ {
ASN1_STRING_free(ret); ASN1_STRING_free(ret);
return(NULL); return NULL;
} }
ret->flags = str->flags; return ret;
return(ret);
} }
int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)