%global major_version 2

Name:           botan2
Version:        2.19.3
Release:        3
Summary:        Crypto and TLS for C++11

License:        BSD
URL:            https://botan.randombit.net/
Source0:        %{url}/releases/Botan-%{version}.tar.xz

Patch01:        Backport-CVE-2024-34703-When-decoding-an-arbi.patch
Patch02:        backport-CVE-2024-39312.patch

BuildRequires:  gcc-c++ python3 python3-devel python3-sphinx python-docutils
BuildRequires:  bzip2-devel zlib-devel make

%description
Botan is a BSD-licensed crypto library written in C++. It provides a
wide variety of basic cryptographic algorithms, X.509 certificates and
CRLs, PKCS \#10 certificate requests, a filter/pipe message processing
system, and a wide variety of other features, all written in portable
C++. The API reference, tutorial, and examples may help impart the
flavor of the library. This is the current stable release branch 2.x
of Botan.


%package        devel
Summary:        Development files for %{name}
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description    devel
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.


%package        doc
Summary:        Documentation for %{name}
BuildArch:      noarch

%description    doc
%{summary}

This package contains HTML documentation for %{name}.


%package -n python3-%{name}
Summary:        Python3 bindings for %{name}
%{?python_provide:%python_provide python3-%{name}}

%description -n python3-%{name}
%{summary}

This package contains the Python3 binding for %{name}.


%prep
%autosetup -n Botan-%{version} -p1


%build
export CXXFLAGS="${CXXFLAGS:-%{optflags}}"

%global enable_modules bzip2,zlib

%{__python3} ./configure.py \
        --prefix=%{_prefix} \
        --libdir=%{_lib} \
        --docdir=%{_docdir} \
        --cc=gcc \
        --os=linux \
        --cpu=%{_arch} \
        --enable-modules=%{enable_modules} \
        --with-python-version=%{python3_version} \
        --with-sphinx \
        --with-rst2man \
        --distribution-info="$(source /etc/os-release ; echo "$NAME")" \
        --disable-static-library \
        --with-debug-info

# work around https://github.com/randombit/botan/issues/2130
%make_build PYTHON_EXE=%{__python3}

%install
make install PYTHON_EXE=%{__python3} DESTDIR=%{buildroot}

sed -e '1{/^#!/d}' -i %{buildroot}%{python3_sitearch}/botan2.py

# doc installation fixups
mv %{buildroot}%{_docdir}/botan-%{version} %{buildroot}%{_pkgdocdir}
rm -r %{buildroot}%{_pkgdocdir}/handbook/{.doctrees,.buildinfo}


%ldconfig_scriptlets


%files
%license license.txt
%dir %{_pkgdocdir}
%{_pkgdocdir}/*.txt
%{_libdir}/libbotan-%{major_version}.so.19*
%{_bindir}/botan
%{_mandir}/man1/botan.1.gz


%files devel
%license license.txt
%{_includedir}/*
%{_libdir}/libbotan-%{major_version}.so
%{_libdir}/pkgconfig/botan-%{major_version}.pc


%files doc
%license license.txt
%dir %{_pkgdocdir}
%{_pkgdocdir}/handbook


%files -n python3-%{name}
%license license.txt
%{python3_sitearch}/%{name}.py
%{python3_sitearch}/__pycache__/*


%check
LD_LIBRARY_PATH=%{buildroot}%{_libdir} ./botan-test


%changelog
* Wed Jul 10 2024 liweigang <liweiganga@uniontech.com> - 2.19.3-3
- fix CVE-2024-39312
- fix CVE-2024-34702

* Tue Jul 02 2024 yinyongkang <yinyongkang@kylinos.cn> - 2.19.3-2
- fix CVE-2024-34703

* Mon Nov 28 2022 liweiganga <liweiganga@uniontech.com> - 2.19.3-1
- update to 2.19.3
- fix CVE-2022-43705

* Thu Jul 14 2022 misaka00251 <misaka00251@misakanet.cn> - 2.19.1-1
- Init package
