summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2026-01-04 19:21:06 +0100
committerCarl Hetherington <cth@carlh.net>2026-01-04 20:35:11 +0100
commit8e7a736467d6f8692c42c614430e37c416b58ac4 (patch)
treecac761f668bfc5831470762c1fdb28dc1c0e6449
parent04b6f3e8f708c8137c074fc0d598b4ee0d10ac39 (diff)
Extract GDC certificate download code to lib/
-rw-r--r--src/lib/download_certificate.cc68
-rw-r--r--src/lib/download_certificate.h32
-rw-r--r--src/lib/wscript1
-rw-r--r--src/wx/download_certificate_panel.h1
-rw-r--r--src/wx/gdc_certificate_panel.cc15
5 files changed, 105 insertions, 12 deletions
diff --git a/src/lib/download_certificate.cc b/src/lib/download_certificate.cc
new file mode 100644
index 000000000..d9560f6a2
--- /dev/null
+++ b/src/lib/download_certificate.cc
@@ -0,0 +1,68 @@
+/*
+ Copyright (C) 2025 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "config.h"
+#include "download_certificate.h"
+#include "internet.h"
+#include <dcp/exceptions.h>
+#include <fmt/format.h>
+#include <string>
+#include <utility>
+
+#include "i18n.h"
+
+
+using std::pair;
+using std::string;
+
+
+static
+pair<dcp::Certificate, string>
+download_gdc_certificate(string const& serial)
+{
+ auto const url = fmt::format(
+ "ftp://{}:{}@ftp.gdc-tech.com/SHA256/{}.crt.pem",
+ Config::instance()->gdc_username().get(),
+ Config::instance()->gdc_password().get(),
+ serial
+ );
+
+ try {
+ return { dcp::Certificate(get_from_url(url, true, false).as_string()), url };
+ } catch (dcp::MiscError& e) {
+ throw CertificateDownloadError(fmt::format(_("Could not read certificate file ({})"), e.what()));
+ }
+}
+
+
+pair<dcp::Certificate, string>
+download_certificate(Manufacturer manufacturer, string const& serial)
+{
+ switch (manufacturer) {
+ case Manufacturer::GDC:
+ return download_gdc_certificate(serial);
+ }
+
+ return {};
+}
+
+
+
diff --git a/src/lib/download_certificate.h b/src/lib/download_certificate.h
new file mode 100644
index 000000000..98998ab4f
--- /dev/null
+++ b/src/lib/download_certificate.h
@@ -0,0 +1,32 @@
+/*
+ Copyright (C) 2025 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include <dcp/certificate.h>
+
+
+enum class Manufacturer
+{
+ GDC,
+};
+
+
+std::pair<dcp::Certificate, std::string> download_certificate(Manufacturer manufacturer, std::string const& serial);
+
diff --git a/src/lib/wscript b/src/lib/wscript
index 8e4b4d783..e17369212 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -89,6 +89,7 @@ sources = """
dkdm_recipient_list.cc
dkdm_wrapper.cc
dolby_cp750.cc
+ download_certificate.cc
email.cc
empty.cc
encode_cli.cc
diff --git a/src/wx/download_certificate_panel.h b/src/wx/download_certificate_panel.h
index 026def299..c53b30009 100644
--- a/src/wx/download_certificate_panel.h
+++ b/src/wx/download_certificate_panel.h
@@ -59,7 +59,6 @@ protected:
wxTextCtrl* _serial;
wxSizer* _overall_sizer;
-private:
boost::optional<dcp::Certificate> _certificate;
boost::optional<std::string> _url;
};
diff --git a/src/wx/gdc_certificate_panel.cc b/src/wx/gdc_certificate_panel.cc
index 05784b94b..83faf2698 100644
--- a/src/wx/gdc_certificate_panel.cc
+++ b/src/wx/gdc_certificate_panel.cc
@@ -23,6 +23,7 @@
#include "gdc_certificate_panel.h"
#include "wx_util.h"
#include "lib/config.h"
+#include "lib/download_certificate.h"
#include "lib/internet.h"
#include <boost/algorithm/string.hpp>
@@ -53,19 +54,10 @@ GDCCertificatePanel::GDCCertificatePanel (DownloadCertificateDialog* dialog)
void
GDCCertificatePanel::do_download ()
{
- string serial = wx_to_std (_serial->GetValue());
+ string serial = wx_to_std(_serial->GetValue());
trim(serial);
- string url = fmt::format(
- "ftp://{}:{}@ftp.gdc-tech.com/SHA256/{}.crt.pem",
- Config::instance()->gdc_username().get(),
- Config::instance()->gdc_password().get(),
- serial
- );
- trim(url);
-
try {
- auto data = get_from_url(url, true, false);
- load_certificate(data, url);
+ std::tie(_certificate, _url) = download_certificate(Manufacturer::GDC, serial);
_dialog->message()->SetLabel(_("Certificate downloaded"));
_dialog->setup_sensitivity ();
} catch (std::exception& e) {
@@ -74,6 +66,7 @@ GDCCertificatePanel::do_download ()
}
}
+
wxString
GDCCertificatePanel::name () const
{