-</code></pre></div><h2 id=description>DESCRIPTION<a class=headerlink href=#description title="Permanent link">¶</a></h2><p>X509v3_get_ext_count() retrieves the number of extensions in <em>x</em>.</p><p>X509v3_get_ext() retrieves extension <em>loc</em> from <em>x</em>. The index <em>loc</em> can take any value from 0 to X509_get_ext_count(<em>x</em>) - 1. The returned extension is an internal pointer which <strong>MUST NOT</strong> be freed by the application.</p><p>X509v3_get_ext_by_NID() and X509v3_get_ext_by_OBJ() look for an extension with <em>nid</em> or <em>obj</em> from extension STACK <em>x</em>. The search starts from the extension after <em>lastpos</em> or from the beginning if <em>lastpos</em> is -1. If the extension is found, its index is returned, otherwise -1 is returned.</p><p>X509v3_get_ext_by_critical() is similar to X509v3_get_ext_by_NID() except it looks for an extension of criticality <em>crit</em>. A zero value for <em>crit</em> looks for a non-critical extension. A nonzero value looks for a critical extension.</p><p>X509v3_delete_ext() deletes the extension with index <em>loc</em> from <em>x</em>. The deleted extension is returned and must be freed by the caller. If <em>loc</em> is an invalid index value, NULL is returned.</p><p>X509v3_add_ext() inserts extension <em>ex</em> to STACK <em>*x</em> at position <em>loc</em>. If <em>loc</em> is -1, the new extension is added to the end. A new STACK is allocated if <em>*x</em> is NULL. The passed extension <em>ex</em> is duplicated so it must be freed after use.</p><p>X509v3_add_extensions() adds the list of extensions <em>exts</em> to STACK <em>*target</em>. The STACK <em>*target</em> is returned unchanged if <em>exts</em> is NULL or an empty list. Otherwise a new stack is allocated if <em>*target</em> is NULL. An extension to be added that has the same OID as a pre-existing one replaces this earlier one.</p><p>X509_get_ext_count(), X509_get_ext(), X509_get_ext_by_NID(), X509_get_ext_by_OBJ(), X509_get_ext_by_critical(), X509_delete_ext() and X509_add_ext() operate on the extensions of certificate <em>x</em>. They are otherwise identical to the X509v3 functions.</p><p>X509_CRL_get_ext_count(), X509_CRL_get_ext(), X509_CRL_get_ext_by_NID(), X509_CRL_get_ext_by_OBJ(), X509_CRL_get_ext_by_critical(), X509_CRL_delete_ext() and X509_CRL_add_ext() operate on the extensions of CRL <em>x</em>. They are otherwise identical to the X509v3 functions.</p><p>X509_REVOKED_get_ext_count(), X509_REVOKED_get_ext(), X509_REVOKED_get_ext_by_NID(), X509_REVOKED_get_ext_by_OBJ(), X509_REVOKED_get_ext_by_critical(), X509_REVOKED_delete_ext() and X509_REVOKED_add_ext() operate on the extensions of CRL entry <em>x</em>. They are otherwise identical to the X509v3 functions.</p><h2 id=notes>NOTES<a class=headerlink href=#notes title="Permanent link">¶</a></h2><p>These functions are used to examine stacks of extensions directly. Applications that want to parse or encode and add an extension should use the extension encode and decode functions instead, such as X509_add1_ext_i2d() and X509_get_ext_d2i().</p><p>For X509v3_get_ext_by_NID(), X509v3_get_ext_by_OBJ(), X509v3_get_ext_by_critical() and its variants, a zero index return value is not an error since extension STACK <em>x</em> indices start from zero. These search functions start from the extension <strong>after</strong> the <em>lastpos</em> parameter so it should initially be set to -1. If it is set to zero, the initial extension will not be checked.</p><p>X509v3_delete_ext() and its variants are a bit counter-intuitive because these functions do not free the extension they delete. They return an <strong>X509_EXTENSION</strong> object which must be explicitly freed using X509_EXTENSION_free().</p><h2 id=return-values>RETURN VALUES<a class=headerlink href=#return-values title="Permanent link">¶</a></h2><p>X509v3_get_ext_count() returns the extension count or 0 for failure.</p><p>X509v3_get_ext(), X509v3_delete_ext() and X509_delete_ext() return an <strong>X509_EXTENSION</strong> structure or NULL if an error occurs.</p><p>X509v3_get_ext_by_OBJ() and X509v3_get_ext_by_critical() return the extension index or -1 if an error occurs.</p><p>X509v3_get_ext_by_NID() returns the extension index or negative values if an error occurs.</p><p>X509v3_add_ext() and X509v3_add_extensions() return a STACK of extensions or NULL on error.</p><p>X509_add_ext() returns 1 on success and 0 on error.</p><h2 id=see-also>SEE ALSO<a class=headerlink href=#see-also title="Permanent link">¶</a></h2><p><a href=../X509V3_get_d2i/ >X509V3_get_d2i(3)</a></p><h2 id=history>HISTORY<a class=headerlink href=#history title="Permanent link">¶</a></h2><p>X509v3_add_extensions() was added in OpenSSL 3.4.</p><h2 id=copyright>COPYRIGHT<a class=headerlink href=#copyright title="Permanent link">¶</a></h2><p>Copyright 2015-2024 The OpenSSL Project Authors. All Rights Reserved.</p><p>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 <a href=https://www.openssl.org/source/license.html>https://www.openssl.org/source/license.html</a>.</p></article></div><script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script></div></main><footer class=md-footer><div class="md-footer-meta md-typeset"><div class="md-footer-meta__inner md-grid"><div class=md-copyright> Made with <a href=https://squidfunk.github.io/mkdocs-material/ target=_blank rel=noopener> Material for MkDocs </a></div></div></div></footer></div><div class=md-dialog data-md-component=dialog><div class="md-dialog__inner md-typeset"></div></div><script id=__config type=application/json>{"base": "../..", "features": ["navigation.indexes", "navigation.instant", "navigation.path", "navigation.prune", "navigation.tabs", "navigation.tabs.sticky", "navigation.tracking", "search.suggest", "toc.follow"], "search": "../../assets/javascripts/workers/search.b8dbb3d2.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": {"default": "master", "provider": "mike"}}</script><script src=../../assets/javascripts/bundle.ad660dcc.min.js></script></body></html>
0 commit comments