EVP_PKEY_GET_ATTR(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸŽ€ NAME πŸŽ€

okay so this is the EVP_PKEY_GET_ATTR(3ossl) manual page, and it's all about the EVP_PKEY X509_ATTRIBUTE functions β€” the little crew that PKCS12 uses. slay πŸ’…

The whole squad:

  • EVP_PKEY_get_attr
  • EVP_PKEY_get_attr_count
  • EVP_PKEY_get_attr_by_NID
  • EVP_PKEY_get_attr_by_OBJ
  • EVP_PKEY_delete_attr
  • EVP_PKEY_add1_attr
  • EVP_PKEY_add1_attr_by_OBJ
  • EVP_PKEY_add1_attr_by_NID
  • EVP_PKEY_add1_attr_by_txt

✨ SYNOPSIS ✨

        #include <openssl/x509.h>

        int EVP_PKEY_get_attr_count(const EVP_PKEY *key);
        int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid, int lastpos);
        int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, const ASN1_OBJECT *obj,
                                     int lastpos);
        X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc);
        X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc);
        int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr);
        int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key,
                                      const ASN1_OBJECT *obj, int type,
                                      const unsigned char *bytes, int len);
        int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key,
                                      int nid, int type,
                                      const unsigned char *bytes, int len);
        int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key,
                                      const char *attrname, int type,
                                      const unsigned char *bytes, int len);

🌸 DESCRIPTION 🌸

These functions are used by PKCS12. That's the vibe. 🫢

  • EVP_PKEY_get_attr_by_OBJ() β€” finds the location of the first matching object obj in the key attribute list. The search starts at the position after lastpos. If the returned value is positive, you can use it on the next call to EVP_PKEY_get_attr_by_OBJ() as the value of lastpos so you can iterate through the remaining attributes. On the first call, lastpos can be set to any negative value so the search starts from the beginning of the attribute list. iykyk ✨
  • EVP_PKEY_get_attr_by_NID() β€” same energy as EVP_PKEY_get_attr_by_OBJ(), except it passes the numerical identifier (NID) nid associated with the object. See <openssl/obj_mac.h> for a list of NID_*. πŸ¦‹
  • EVP_PKEY_get_attr() β€” returns the X509_ATTRIBUTE object at index loc in the key attribute list. loc should be in the range from 0 to EVP_PKEY_get_attr_count() - 1. literally stay in bounds, bestie.
  • EVP_PKEY_delete_attr() β€” removes the X509_ATTRIBUTE object at index loc in the key attribute list. πŸ’…
  • EVP_PKEY_add1_attr() β€” pushes a copy of the passed-in X509_ATTRIBUTE object to the key attribute list. A new key attribute list is created if required. An error occurs if either attr is NULL, or the attribute already exists. no duplicates allowed, periodt. πŸ’€
  • EVP_PKEY_add1_attr_by_OBJ() β€” creates a new X509_ATTRIBUTE using X509_ATTRIBUTE_set1_object() and X509_ATTRIBUTE_set1_data() to assign a new obj with type type and data bytes of length len, and then pushes it to the key object's attribute list. If obj already exists in the attribute list, then an error occurs. πŸŽ€
  • EVP_PKEY_add1_attr_by_NID() β€” similar to EVP_PKEY_add1_attr_by_OBJ(), except it passes the numerical identifier (NID) nid associated with the object. See <openssl/obj_mac.h> for a list of NID_*. 🌈
  • EVP_PKEY_add1_attr_by_txt() β€” similar to EVP_PKEY_add1_attr_by_OBJ(), except it passes a name attrname associated with the object. See <openssl/obj_mac.h> for a list of SN_* names. ⭐

πŸ’… RETURN VALUES πŸ’…

  • EVP_PKEY_get_attr_count() β€” returns the number of attributes in the key object attribute list, or -1 if the attribute list is NULL. πŸ™ˆ
  • EVP_PKEY_get_attr_by_OBJ() β€” returns -1 if either the list is empty OR the object is not found; otherwise it returns the location of the object in the list. πŸ”₯
  • EVP_PKEY_get_attr_by_NID() β€” similar to EVP_PKEY_get_attr_by_OBJ(), except that it returns -2 if the nid is not known by OpenSSL. extra special error code, bestie. 😭
  • EVP_PKEY_get_attr() β€” returns either an X509_ATTRIBUTE or NULL if there is an error. πŸ¦‹
  • EVP_PKEY_delete_attr() β€” returns either the removed X509_ATTRIBUTE or NULL if there is an error. πŸ’œ
  • EVP_PKEY_add1_attr(), EVP_PKEY_add1_attr_by_OBJ(), EVP_PKEY_add1_attr_by_NID() and EVP_PKEY_add1_attr_by_txt() β€” return 1 on success or 0 otherwise. slay. βœ…

πŸ¦‹ NOTES πŸ¦‹

A EVP_PKEY object's attribute list is initially NULL.

⚠️ Important vibe check: all the functions listed above will return an error unless EVP_PKEY_add1_attr() is called. fr fr, do not skip that step. πŸ’€

All functions listed assume that the key is not NULL. no cap. 🌸


πŸ”₯ SEE ALSO πŸ”₯


Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use 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>.


mwah πŸ’‹ β€” this cutie is from OpenSSL 3.5.6, dated 2026-04-07. πŸ‘‘βœ¨

πŸ“¦ where this page comes from