Skip to content

Commit 74e50ea

Browse files
committed
use a builder style api instead
1 parent 60770c7 commit 74e50ea

File tree

10 files changed

+542
-645
lines changed

10 files changed

+542
-645
lines changed

doc/api_ref/ffi.rst

Lines changed: 89 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,116 +1791,15 @@ X.509 Certificates
17911791
Return a (statically allocated) string associated with the verification
17921792
result, or NULL if the code is not known.
17931793

1794-
.. cpp:type:: opaque* botan_x509_cert_opts_t
1795-
1796-
An opaque data type for X.509 certificate options. Don't mess with it.
1797-
1798-
.. cpp:type:: opaque* botan_x509_time_t
1799-
1800-
An opaque data type for an X.509 time. Don't mess with it.
1801-
1802-
.. cpp:type:: opaque* botan_x509_ext_as_blocks_t
1803-
1804-
An opaque data type for an X.509 AS Blocks extension (RFC 3779). Don't mess with it.
18051794

18061795
.. cpp:type:: opaque* botan_x509_ext_ip_addr_blocks_t
18071796

18081797
An opaque data type for an X.509 IP Address Blocks extension (RFC 3779). Don't mess with it.
18091798

1810-
.. cpp:type:: opaque* botan_x509_ca_t
1811-
1812-
An opaque data type for an X.509 CA. Don't mess with it.
1813-
1814-
.. cpp:type:: opaque* botan_x509_pkcs10_req_t
1815-
1816-
An opaque data type for a PKCS #10 certificate request. Don't mess with it.
1817-
1818-
.. cpp:function::int botan_x509_cert_opts_destroy(botan_x509_cert_opts_t opts)
1819-
1820-
Destroy the options object.
1821-
1822-
.. cpp:function::int botan_x509_time_destroy(botan_x509_time_t time)
1823-
1824-
Destroy the time object.
1825-
18261799
.. cpp:function::int botan_x509_ext_ip_addr_blocks_destroy(botan_x509_ext_ip_addr_blocks_t ip_addr_blocks)
18271800

18281801
Destroy the IP Address Blocks object.
18291802

1830-
.. cpp:function::int botan_x509_ext_as_blocks_destroy(botan_x509_ext_as_blocks_t as_blocks)
1831-
1832-
Destroy the AS Blocks object.
1833-
1834-
.. cpp:function::int botan_x509_ca_destroy(botan_x509_ca_t ca)
1835-
1836-
Destroy the CA object.
1837-
1838-
.. cpp:function::int botan_x509_pkcs10_req_destroy(botan_x509_pkcs10_req_t req)
1839-
1840-
Destroy the PKCS #10 certificate request object.
1841-
1842-
.. cpp:function::int int botan_x509_create_cert_opts(botan_x509_cert_opts_t* opts_obj, const char* opts, uint32_t* expire_time)
1843-
1844-
Creates a new options object. ``opts`` defines the common name (e.g. `common_name/country/organization/organizational_unit`), ``expire_time`` if given
1845-
is the expiration time from current clock in seconds.
1846-
1847-
.. cpp:function::int botan_x509_cert_opts_common_name(botan_x509_cert_opts_t opts, const char* name)
1848-
1849-
Set the common name for the object.
1850-
1851-
.. cpp:function::int botan_x509_cert_opts_country(botan_x509_cert_opts_t opts, const char* country)
1852-
1853-
Set the country for the objects.
1854-
1855-
.. cpp:function::int botan_x509_cert_opts_organization(botan_x509_cert_opts_t opts, const char* organization)
1856-
1857-
.. cpp:function::int botan_x509_cert_opts_org_unit(botan_x509_cert_opts_t opts, const char* org_unit)
1858-
1859-
.. cpp:function::int botan_x509_cert_opts_locality(botan_x509_cert_opts_t opts, const char* locality)
1860-
1861-
.. cpp:function::int botan_x509_cert_opts_state(botan_x509_cert_opts_t opts, const char* state)
1862-
1863-
.. cpp:function::int botan_x509_cert_opts_serial_number(botan_x509_cert_opts_t opts, const char* serial_number)
1864-
1865-
.. cpp:function::int botan_x509_cert_opts_email(botan_x509_cert_opts_t opts, const char* email)
1866-
1867-
.. cpp:function::int botan_x509_cert_opts_uri(botan_x509_cert_opts_t opts, const char* uri)
1868-
1869-
.. cpp:function::int botan_x509_cert_opts_ip(botan_x509_cert_opts_t opts, const char* ip)
1870-
1871-
.. cpp:function::int botan_x509_cert_opts_dns(botan_x509_cert_opts_t opts, const char* dns)
1872-
1873-
.. cpp:function::int botan_x509_cert_opts_xmpp(botan_x509_cert_opts_t opts, const char* xmpp)
1874-
1875-
.. cpp:function::int botan_x509_cert_opts_challenge(botan_x509_cert_opts_t opts, const char* challenge)
1876-
1877-
.. cpp:function::int int botan_x509_cert_opts_more_org_units(botan_x509_cert_opts_t opts, const char** more_org_units, size_t cnt)
1878-
1879-
.. cpp:function::int int botan_x509_cert_opts_more_dns(botan_x509_cert_opts_t opts, const char** more_dns, size_t cnt)
1880-
1881-
.. cpp:function::int botan_x509_cert_opts_ca_key(botan_x509_cert_opts_t opts, size_t limit)
1882-
1883-
Mark the certificate for CA usage.
1884-
1885-
.. cpp:function::int botan_x509_cert_opts_padding_scheme(botan_x509_cert_opts_t opts, const char* scheme)
1886-
1887-
.. cpp:function::int botan_x509_cert_opts_not_before(botan_x509_cert_opts_t opts, botan_x509_time_t not_before)
1888-
1889-
.. cpp:function::int botan_x509_cert_opts_not_after(botan_x509_cert_opts_t opts, botan_x509_time_t not_after)
1890-
1891-
.. cpp:function::int botan_x509_cert_opts_constraints(botan_x509_cert_opts_t opts, uint32_t usage)
1892-
1893-
.. cpp:function::int botan_x509_cert_opts_ex_constraint(botan_x509_cert_opts_t opts, botan_asn1_oid_t oid)
1894-
1895-
.. cpp:function::int botan_x509_create_time(botan_x509_time_t* time_obj, uint64_t time_since_epoch)
1896-
1897-
Create a new time object.
1898-
1899-
.. cpp:function::int int botan_x509_cert_opts_ext_ip_addr_blocks(botan_x509_cert_opts_t opts, \
1900-
botan_x509_ext_ip_addr_blocks_t ip_addr_blocks)
1901-
1902-
.. cpp:function::int int botan_x509_cert_opts_ext_as_blocks(botan_x509_cert_opts_t opts, botan_x509_ext_as_blocks_t as_blocks)
1903-
19041803
.. cpp:function::int botan_x509_ext_create_ip_addr_blocks(botan_x509_ext_ip_addr_blocks_t* ip_addr_blocks)
19051804

19061805
Create a new IP Address Blocks object.
@@ -1910,8 +1809,11 @@ X.509 Certificates
19101809

19111810
Get an IP Address Blocks object from a certificate. Cannot be mutated.
19121811

1913-
.. cpp:function::int int botan_x509_ext_ip_addr_blocks_add_ip_addr(
1914-
botan_x509_ext_ip_addr_blocks_t ip_addr_blocks, const uint8_t* min, const uint8_t* max, int ipv6, uint8_t* safi)
1812+
.. cpp:function::int int botan_x509_ext_ip_addr_blocks_add_ip_addr(botan_x509_ext_ip_addr_blocks_t ip_addr_blocks, \
1813+
const uint8_t* min, \
1814+
const uint8_t* max, \
1815+
int ipv6, \
1816+
uint8_t* safi)
19151817

19161818
Add a new IP Address to the extension. Set ``ipv6`` to 0 if the address is v4, 1 if it is v6.
19171819
``safi`` may be NULL.
@@ -1966,6 +1868,14 @@ X.509 Certificates
19661868
``min_out`` and ``max_out`` will be set to the minimum and maximum of the IP range.
19671869
You must provide 4 / 16 bytes of buffer space for each for IP v4 / v6 respectively.
19681870

1871+
.. cpp:type:: opaque* botan_x509_ext_as_blocks_t
1872+
1873+
An opaque data type for an X.509 AS Blocks extension (RFC 3779). Don't mess with it.
1874+
1875+
.. cpp:function::int botan_x509_ext_as_blocks_destroy(botan_x509_ext_as_blocks_t as_blocks)
1876+
1877+
Destroy the AS Blocks object.
1878+
19691879
.. cpp:function::int botan_x509_ext_create_as_blocks(botan_x509_ext_as_blocks_t* as_blocks)
19701880

19711881
Create a new AS Blocks object.
@@ -2005,23 +1915,82 @@ X.509 Certificates
20051915

20061916
.. cpp:function::int int botan_x509_ext_as_blocks_get_rdi_at(botan_x509_ext_as_blocks_t as_blocks, size_t i, uint32_t* min, uint32_t* max)
20071917

1918+
.. cpp:type:: opaque* botan_x509_cert_params_builder_t
1919+
1920+
.. cpp:function::int botan_x509_cert_opts_destroy(botan_x509_cert_opts_t opts)
1921+
1922+
Destroy the options object.
1923+
1924+
.. cpp:function::int botan_x509_create_cert_params_builder(botan_x509_cert_params_builder_t* builder_obj, \
1925+
const char* opts, \
1926+
uint32_t* expire_time);
1927+
1928+
Create a new certificate builder object. ``opts`` defines the common name (e.g. `common_name/country/organization/organizational_unit`).
1929+
``expire_time`` if given is the expiration time from current clock in seconds.
1930+
1931+
.. cpp:function::int botan_x509_cert_params_builder_add_common_name(botan_x509_cert_params_builder_t builder, const char* name);
1932+
1933+
.. cpp:function::int botan_x509_cert_params_builder_add_country(botan_x509_cert_params_builder_t builder, const char* country);
1934+
1935+
.. cpp:function::int botan_x509_cert_params_builder_add_organization(botan_x509_cert_params_builder_t builder, const char* organization);
1936+
1937+
.. cpp:function::int botan_x509_cert_params_builder_add_org_unit(botan_x509_cert_params_builder_t builder, const char* org_unit);
1938+
1939+
.. cpp:function::int botan_x509_cert_params_builder_add_locality(botan_x509_cert_params_builder_t builder, const char* locality);
1940+
1941+
.. cpp:function::int botan_x509_cert_params_builder_add_state(botan_x509_cert_params_builder_t builder, const char* state);
1942+
1943+
.. cpp:function::int botan_x509_cert_params_builder_add_serial_number(botan_x509_cert_params_builder_t builder, const char* serial_number);
1944+
1945+
.. cpp:function::int botan_x509_cert_params_builder_add_email(botan_x509_cert_params_builder_t builder, const char* email);
1946+
1947+
.. cpp:function::int botan_x509_cert_params_builder_add_uri(botan_x509_cert_params_builder_t builder, const char* uri);
1948+
1949+
.. cpp:function::int botan_x509_cert_params_builder_add_ip(botan_x509_cert_params_builder_t builder, const char* ip);
1950+
1951+
.. cpp:function::int botan_x509_cert_params_builder_add_dns(botan_x509_cert_params_builder_t builder, const char* dns);
1952+
1953+
.. cpp:function::int botan_x509_cert_params_builder_add_xmpp(botan_x509_cert_params_builder_t builder, const char* xmpp);
1954+
1955+
.. cpp:function::int botan_x509_cert_params_builder_add_challenge(botan_x509_cert_params_builder_t builder, const char* challenge);
1956+
1957+
.. cpp:function::int botan_x509_cert_params_builder_mark_as_ca_key(botan_x509_cert_params_builder_t builder, size_t limit);
1958+
1959+
Mark the certificate for CA usage.
1960+
1961+
.. cpp:function::int botan_x509_cert_params_builder_add_not_before(botan_x509_cert_params_builder_t builder, uint64_t time_since_epoch);
1962+
1963+
``time_since_epoch`` is expected to be in seconds.
1964+
1965+
.. cpp:function::int botan_x509_cert_params_builder_add_not_after(botan_x509_cert_params_builder_t builder, uint64_t time_since_epoch);
1966+
1967+
.. cpp:function::int botan_x509_cert_params_builder_add_constraints(botan_x509_cert_params_builder_t builder, uint32_t usage);
1968+
1969+
.. cpp:function::int botan_x509_cert_params_builder_add_ex_constraint(botan_x509_cert_params_builder_t builder, botan_asn1_oid_t oid);
1970+
1971+
.. cpp:function::int botan_x509_cert_params_builder_add_ext_ip_addr_blocks(botan_x509_cert_params_builder_t builder, \
1972+
botan_x509_ext_ip_addr_blocks_t ip_addr_blocks);
1973+
1974+
.. cpp:function::int botan_x509_cert_params_builder_add_ext_as_blocks(botan_x509_cert_params_builder_t builder, \
1975+
botan_x509_ext_as_blocks_t as_blocks);
1976+
20081977
.. cpp:function::int int botan_x509_create_self_signed_cert(botan_x509_cert_t* cert_obj, \
20091978
botan_privkey_t key, \
20101979
botan_x509_cert_opts_t opts, \
20111980
const char* hash_fn, \
2012-
const char* sig_padding, \
1981+
const char* padding, \
20131982
botan_rng_t rng)
20141983

1984+
20151985
Create a new self-signed X.509 certificate.
20161986

2017-
.. cpp:function::int int botan_x509_create_ca(botan_x509_ca_t* ca_obj, \
2018-
botan_x509_cert_t ca_cert, \
2019-
botan_privkey_t key, \
2020-
const char* hash_fn, \
2021-
const char* sig_padding, \
2022-
botan_rng_t rng)
1987+
.. cpp:type:: opaque* botan_x509_pkcs10_req_t
20231988

2024-
Create a CA object capable of signing other certificates.
1989+
An opaque data type for a PKCS #10 certificate request. Don't mess with it.
1990+
1991+
.. cpp:function::int botan_x509_pkcs10_req_destroy(botan_x509_pkcs10_req_t req)
1992+
1993+
Destroy the PKCS #10 certificate request object.
20251994

20261995
.. cpp:function::int int botan_x509_create_pkcs10_req(botan_x509_pkcs10_req_t* req_obj, \
20271996
botan_x509_cert_opts_t opts, \
@@ -2031,14 +2000,17 @@ X.509 Certificates
20312000

20322001
Create a PCKS #10 certificate request.
20332002

2034-
.. cpp:function::int int botan_x509_sign_req(botan_x509_cert_t* cert_obj, \
2035-
botan_x509_ca_t ca, \
2036-
botan_x509_pkcs10_req_t req, \
2003+
.. cpp:function::int int botan_x509_sign_req(botan_x509_cert_t* subject_cert, \
2004+
botan_x509_pkcs10_req_t subject_req, \
2005+
botan_x509_cert_t issuing_cert, \
2006+
botan_privkey_t issuing_key, \
20372007
botan_rng_t rng, \
2038-
botan_x509_time_t not_before, \
2039-
botan_x509_time_t not_after)
2008+
uint64_t not_before, \
2009+
uint64_t not_after, \
2010+
const char* hash_fn, \
2011+
const char* padding)
20402012

2041-
Sign a PKCS #10 certificate request
2013+
Sign a PKCS #10 certificate request. ``not_before`` and ``not_after`` are expected to be the time since the UNIX epoch, in seconds.
20422014

20432015
X.509 Certificate Revocation Lists
20442016
----------------------------------------

doc/api_ref/python.rst

Lines changed: 33 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -715,80 +715,58 @@ HOTP
715715
in. If the code did verify and resync_range was zero, then the
716716
next counter will always be counter+1.
717717
718-
X509Time
718+
X509CertificateBuilder
719719
-----------------------------------------
720720
.. versionadded:: 3.9.0
721721
722-
.. py:class:: X509Time(time_since_epoch)
722+
.. py:class:: X509CertificateBuilder(opts, expire_time=None)
723723
724-
PKCS10Req
725-
-----------------------------------------
726-
.. versionadded:: 3.9.0
727-
728-
.. py:class:: PKCS10Req()
729-
730-
X509Opts
731-
-----------------------------------------
732-
.. versionadded:: 3.9.0
733-
734-
.. py:class:: X509Opts(opts, expire_time=None)
724+
.. py:method:: add_common_name(name)
735725
736-
.. py:method:: set_common_name(name)
726+
.. py:method:: add_country(country)
737727
738-
Set the common name for the certificate.
728+
.. py:method:: add_organization(organization)
739729
740-
.. py:method:: set_country(country)
730+
.. py:method:: add_org_unit(org_unit)
741731
742-
.. py:method:: set_organization(organization)
732+
.. py:method:: add_locality(locality)
743733
744-
.. py:method:: set_org_unit(org_unit)
734+
.. py:method:: add_state(state)
745735
746-
.. py:method:: set_locality(locality)
736+
.. py:method:: add_serial_number(serial_number)
747737
748-
.. py:method:: set_state(state)
738+
.. py:method:: add_email(email)
749739
750-
.. py:method:: set_serial_number(serial_number)
740+
.. py:method:: add_uri(uri)
751741
752-
.. py:method:: set_email(email)
742+
.. py:method:: add_ip(ip)
753743
754-
.. py:method:: set_uri(uri)
744+
.. py:method:: add_dns(dns)
755745
756-
.. py:method:: set_ip(ip)
746+
.. py:method:: add_xmpp(xmpp)
757747
758-
.. py:method:: set_dns(dns)
748+
.. py:method:: add_challenge(challenge)
759749
760-
.. py:method:: set_xmpp(xmpp)
750+
.. py:method:: mark_as_ca_key(limit)
761751
762-
.. py:method:: set_challenge(challenge)
752+
.. py:method:: add_not_before(time_since_epoch)
763753
764-
.. py:method:: set_more_org_units(more_org_units)
754+
``time_since_epoch`` is expected to be in seconds.
765755
766-
``more_org_units`` is expected to be a of type ``list[string]``
756+
.. py:method:: add_not_after(time_since_epoch)
767757
768-
.. py:method:: set_more_dns(more_dns)
758+
.. py:method:: add_constraints(usage_list)
769759
770-
``more_dns`` is expected to be a of type ``list[string]``
771-
772-
.. py:method:: set_ca_key(limit)
773-
774-
.. py:method:: set_padding_scheme(scheme)
775-
776-
.. py:method:: set_not_before(not_before)
777-
778-
.. py:method:: set_not_after(not_after)
760+
.. py:method:: add_ex_constraints(oid)
779761
780-
.. py:method:: set_constraints(usage_list)
762+
.. py:method:: add_ext_ip_addr_blocks(ip_addr_blocks)
781763
782-
.. py:method:: add_ex_constraints(oid)
764+
.. py:method:: add_ext_as_blocks(as_blocks)
783765
784766
.. py:method:: create_req(key, hash_fn, rng)
785767
786768
Create a PKCS #10 certificate request that can later be signed.
787769
788-
.. py:method:: add_ext_ip_addr_blocks(ip_addr_blocks)
789-
790-
.. py:method:: add_ext_as_blocks(as_blocks)
791-
792770
X509ExtIPAddrBlocks
793771
-----------------------------------------
794772
@@ -855,6 +833,16 @@ X509ExtASBlocks
855833
856834
.. py:method:: rdi()
857835
836+
PKCS10Req
837+
-----------------------------------------
838+
.. versionadded:: 3.9.0
839+
840+
.. py:class:: PKCS10Req()
841+
842+
.. py:method:: sign(issuing_cert, issuing_key, rng, not_before, not_after, hash_fn, padding)
843+
844+
``not_before`` and ``not_after`` are expected to be the time since the UNIX epoch, in seconds.
845+
858846
X509Cert
859847
-----------------------------------------
860848
@@ -1002,17 +990,6 @@ X509Cert
1002990
1003991
Check if the certificate (``self``) is revoked on the given ``crl``.
1004992
1005-
X509Ca
1006-
-----------------------------------------
1007-
1008-
.. versionadded:: 3.9.0
1009-
1010-
.. py:class:: X509Ca(cert, key, rng, has_fn, sig_padding="")
1011-
1012-
.. py:method:: sign(req, rng, not_before, not_after)
1013-
1014-
Sign a PKCS #10 certificate request.
1015-
1016993
X509CRL
1017994
-----------------------------------------
1018995

0 commit comments

Comments
 (0)