-/* $OpenBSD: x_pubkey.c,v 1.31 2021/12/25 13:17:48 jsing Exp $ */
+/* $OpenBSD: x_pubkey.c,v 1.32 2022/05/24 19:59:14 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
{
if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval))
return 0;
- if (penc) {
- free(pub->public_key->data);
- pub->public_key->data = penc;
- pub->public_key->length = penclen;
- /* Set number of unused bits to zero */
- pub->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
- pub->public_key->flags |= ASN1_STRING_FLAG_BITS_LEFT;
- }
- return 1;
+
+ if (penc == NULL)
+ return 1;
+
+ ASN1_STRING_set0(pub->public_key, penc, penclen);
+
+ return asn1_abs_set_unused_bits(pub->public_key, 0);
}
int