xref: /freebsd/crypto/openssl/doc/man3/EVP_PKEY_get_attr.pod (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1*e0c4386eSCy Schubert=pod
2*e0c4386eSCy Schubert
3*e0c4386eSCy Schubert=head1 NAME
4*e0c4386eSCy Schubert
5*e0c4386eSCy SchubertEVP_PKEY_get_attr,
6*e0c4386eSCy SchubertEVP_PKEY_get_attr_count,
7*e0c4386eSCy SchubertEVP_PKEY_get_attr_by_NID, EVP_PKEY_get_attr_by_OBJ,
8*e0c4386eSCy SchubertEVP_PKEY_delete_attr,
9*e0c4386eSCy SchubertEVP_PKEY_add1_attr,
10*e0c4386eSCy SchubertEVP_PKEY_add1_attr_by_OBJ, EVP_PKEY_add1_attr_by_NID, EVP_PKEY_add1_attr_by_txt
11*e0c4386eSCy Schubert- EVP_PKEY B<X509_ATTRIBUTE> functions
12*e0c4386eSCy Schubert
13*e0c4386eSCy Schubert=head1 SYNOPSIS
14*e0c4386eSCy Schubert
15*e0c4386eSCy Schubert #include <openssl/x509.h>
16*e0c4386eSCy Schubert
17*e0c4386eSCy Schubert int EVP_PKEY_get_attr_count(const EVP_PKEY *key);
18*e0c4386eSCy Schubert int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid, int lastpos);
19*e0c4386eSCy Schubert int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, const ASN1_OBJECT *obj,
20*e0c4386eSCy Schubert                              int lastpos);
21*e0c4386eSCy Schubert X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc);
22*e0c4386eSCy Schubert X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc);
23*e0c4386eSCy Schubert int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr);
24*e0c4386eSCy Schubert int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key,
25*e0c4386eSCy Schubert                               const ASN1_OBJECT *obj, int type,
26*e0c4386eSCy Schubert                               const unsigned char *bytes, int len);
27*e0c4386eSCy Schubert int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key,
28*e0c4386eSCy Schubert                               int nid, int type,
29*e0c4386eSCy Schubert                               const unsigned char *bytes, int len);
30*e0c4386eSCy Schubert int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key,
31*e0c4386eSCy Schubert                               const char *attrname, int type,
32*e0c4386eSCy Schubert                               const unsigned char *bytes, int len);
33*e0c4386eSCy Schubert
34*e0c4386eSCy Schubert=head1 DESCRIPTION
35*e0c4386eSCy Schubert
36*e0c4386eSCy SchubertThese functions are used by B<PKCS12>.
37*e0c4386eSCy Schubert
38*e0c4386eSCy SchubertEVP_PKEY_get_attr_by_OBJ() finds the location of the first matching object I<obj>
39*e0c4386eSCy Schubertin the I<key> attribute list. The search starts at the position after I<lastpos>.
40*e0c4386eSCy SchubertIf the returned value is positive then it can be used on the next call to
41*e0c4386eSCy SchubertEVP_PKEY_get_attr_by_OBJ() as the value of I<lastpos> in order to iterate through
42*e0c4386eSCy Schubertthe remaining attributes. I<lastpos> can be set to any negative value on the
43*e0c4386eSCy Schubertfirst call, in order to start searching from the start of the attribute list.
44*e0c4386eSCy Schubert
45*e0c4386eSCy SchubertEVP_PKEY_get_attr_by_NID() is similar to EVP_PKEY_get_attr_by_OBJ() except that
46*e0c4386eSCy Schubertit passes the numerical identifier (NID) I<nid> associated with the object.
47*e0c4386eSCy SchubertSee <openssl/obj_mac.h> for a list of NID_*.
48*e0c4386eSCy Schubert
49*e0c4386eSCy SchubertEVP_PKEY_get_attr() returns the B<X509_ATTRIBUTE> object at index I<loc> in the
50*e0c4386eSCy SchubertI<key> attribute list. I<loc> should be in the range from 0 to
51*e0c4386eSCy SchubertEVP_PKEY_get_attr_count() - 1.
52*e0c4386eSCy Schubert
53*e0c4386eSCy SchubertEVP_PKEY_delete_attr() removes the B<X509_ATTRIBUTE> object at index I<loc> in
54*e0c4386eSCy Schubertthe I<key> attribute list.
55*e0c4386eSCy Schubert
56*e0c4386eSCy SchubertEVP_PKEY_add1_attr() pushes a copy of the passed in B<X509_ATTRIBUTE> object
57*e0c4386eSCy Schubertto the I<key> attribute list. A new I<key> attribute list is created if required.
58*e0c4386eSCy SchubertAn error occurs if either I<attr> is NULL, or the attribute already exists.
59*e0c4386eSCy Schubert
60*e0c4386eSCy SchubertEVP_PKEY_add1_attr_by_OBJ() creates a new B<X509_ATTRIBUTE> using
61*e0c4386eSCy SchubertX509_ATTRIBUTE_set1_object() and X509_ATTRIBUTE_set1_data() to assign a new
62*e0c4386eSCy SchubertI<obj> with type I<type> and data I<bytes> of length I<len> and then pushes it
63*e0c4386eSCy Schubertto the I<key> object's attribute list. If I<obj> already exists in the attribute
64*e0c4386eSCy Schubertlist then an error occurs.
65*e0c4386eSCy Schubert
66*e0c4386eSCy SchubertEVP_PKEY_add1_attr_by_NID() is similar to EVP_PKEY_add1_attr_by_OBJ() except
67*e0c4386eSCy Schubertthat it passes the numerical identifier (NID) I<nid> associated with the object.
68*e0c4386eSCy SchubertSee <openssl/obj_mac.h> for a list of NID_*.
69*e0c4386eSCy Schubert
70*e0c4386eSCy SchubertEVP_PKEY_add1_attr_by_txt() is similar to EVP_PKEY_add1_attr_by_OBJ() except
71*e0c4386eSCy Schubertthat it passes a name I<attrname> associated with the object.
72*e0c4386eSCy SchubertSee <openssl/obj_mac.h> for a list of SN_* names.
73*e0c4386eSCy Schubert
74*e0c4386eSCy Schubert=head1 RETURN VALUES
75*e0c4386eSCy Schubert
76*e0c4386eSCy SchubertEVP_PKEY_get_attr_count() returns the number of attributes in the I<key> object
77*e0c4386eSCy Schubertattribute list or -1 if the attribute list is NULL.
78*e0c4386eSCy Schubert
79*e0c4386eSCy SchubertEVP_PKEY_get_attr_by_OBJ() returns -1 if either the list is empty OR the object
80*e0c4386eSCy Schubertis not found, otherwise it returns the location of the object in the list.
81*e0c4386eSCy Schubert
82*e0c4386eSCy SchubertEVP_PKEY_get_attr_by_NID() is similar to EVP_PKEY_get_attr_by_OBJ(), except that
83*e0c4386eSCy Schubertit returns -2 if the I<nid> is not known by OpenSSL.
84*e0c4386eSCy Schubert
85*e0c4386eSCy SchubertEVP_PKEY_get_attr() returns either a B<X509_ATTRIBUTE> or NULL if there is a
86*e0c4386eSCy Schuberterror.
87*e0c4386eSCy Schubert
88*e0c4386eSCy SchubertEVP_PKEY_delete_attr() returns either the removed B<X509_ATTRIBUTE> or NULL if
89*e0c4386eSCy Schubertthere is a error.
90*e0c4386eSCy Schubert
91*e0c4386eSCy SchubertEVP_PKEY_add1_attr(), EVP_PKEY_add1_attr_by_OBJ(), EVP_PKEY_add1_attr_by_NID()
92*e0c4386eSCy Schubertand EVP_PKEY_add1_attr_by_txt() return 1 on success or 0 otherwise.
93*e0c4386eSCy Schubert
94*e0c4386eSCy Schubert=head1 NOTES
95*e0c4386eSCy Schubert
96*e0c4386eSCy SchubertA B<EVP_PKEY> object's attribute list is initially NULL. All the above functions
97*e0c4386eSCy Schubertlisted will return an error unless EVP_PKEY_add1_attr() is called.
98*e0c4386eSCy SchubertAll functions listed assume that the I<key> is not NULL.
99*e0c4386eSCy Schubert
100*e0c4386eSCy Schubert=head1 SEE ALSO
101*e0c4386eSCy Schubert
102*e0c4386eSCy SchubertL<X509_ATTRIBUTE(3)>
103*e0c4386eSCy Schubert
104*e0c4386eSCy Schubert=head1 COPYRIGHT
105*e0c4386eSCy Schubert
106*e0c4386eSCy SchubertCopyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
107*e0c4386eSCy Schubert
108*e0c4386eSCy SchubertLicensed under the Apache License 2.0 (the "License").  You may not use
109*e0c4386eSCy Schubertthis file except in compliance with the License.  You can obtain a copy
110*e0c4386eSCy Schubertin the file LICENSE in the source distribution or at
111*e0c4386eSCy SchubertL<https://www.openssl.org/source/license.html>.
112*e0c4386eSCy Schubert
113*e0c4386eSCy Schubert=cut
114