2016-05-18 02:52:22 +08:00
|
|
|
/*
|
2020-05-15 21:09:49 +08:00
|
|
|
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
|
1998-12-21 18:52:47 +08:00
|
|
|
*
|
2018-12-06 21:00:36 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:52:22 +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>
|
2000-12-09 03:09:35 +08:00
|
|
|
#include <openssl/asn1t.h>
|
1999-07-22 06:10:23 +08:00
|
|
|
#include <openssl/x509.h>
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "x509_local.h"
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2014-12-28 10:48:40 +08:00
|
|
|
/*-
|
|
|
|
* X509_ATTRIBUTE: this has the following form:
|
2000-12-09 03:09:35 +08:00
|
|
|
*
|
|
|
|
* typedef struct x509_attributes_st
|
2015-01-22 11:40:55 +08:00
|
|
|
* {
|
|
|
|
* ASN1_OBJECT *object;
|
2015-03-25 23:08:55 +08:00
|
|
|
* STACK_OF(ASN1_TYPE) *set;
|
2015-01-22 11:40:55 +08:00
|
|
|
* } X509_ATTRIBUTE;
|
2000-12-09 03:09:35 +08:00
|
|
|
*
|
|
|
|
*/
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-12-09 03:09:35 +08:00
|
|
|
ASN1_SEQUENCE(X509_ATTRIBUTE) = {
|
2015-01-22 11:40:55 +08:00
|
|
|
ASN1_SIMPLE(X509_ATTRIBUTE, object, ASN1_OBJECT),
|
2015-03-25 23:08:55 +08:00
|
|
|
ASN1_SET_OF(X509_ATTRIBUTE, set, ASN1_ANY)
|
2001-02-23 20:47:06 +08:00
|
|
|
} ASN1_SEQUENCE_END(X509_ATTRIBUTE)
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-12-09 03:09:35 +08:00
|
|
|
IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE)
|
2001-07-27 10:22:42 +08:00
|
|
|
IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE)
|
1998-12-21 18:52:47 +08:00
|
|
|
|
1999-05-10 00:39:11 +08:00
|
|
|
X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
X509_ATTRIBUTE *ret = NULL;
|
|
|
|
ASN1_TYPE *val = NULL;
|
2020-06-05 06:30:00 +08:00
|
|
|
ASN1_OBJECT *oid;
|
1998-12-21 19:00:56 +08:00
|
|
|
|
2020-06-05 06:30:00 +08:00
|
|
|
if ((oid = OBJ_nid2obj(nid)) == NULL)
|
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
if ((ret = X509_ATTRIBUTE_new()) == NULL)
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2020-06-05 06:30:00 +08:00
|
|
|
ret->object = oid;
|
2015-01-22 11:40:55 +08:00
|
|
|
if ((val = ASN1_TYPE_new()) == NULL)
|
|
|
|
goto err;
|
2015-03-25 23:08:55 +08:00
|
|
|
if (!sk_ASN1_TYPE_push(ret->set, val))
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
1998-12-21 19:00:56 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
ASN1_TYPE_set(val, atrtype, value);
|
2017-10-17 22:04:09 +08:00
|
|
|
return ret;
|
2015-01-22 11:40:55 +08:00
|
|
|
err:
|
2015-05-01 05:33:59 +08:00
|
|
|
X509_ATTRIBUTE_free(ret);
|
2015-04-30 23:30:03 +08:00
|
|
|
ASN1_TYPE_free(val);
|
2017-10-17 22:04:09 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|