ctb_formats_pem/pem.rs
1// SPDX-License-Identifier: AGPL-3.0-or-later
2/*
3This file is part of Collective Toolbox, a database and document workspace and utilities.
4Copyright (C) 2026 Collective Toolbox Developers
5Contact: info@collectivetoolbox.com
6
7This program is free software: you can redistribute it and/or modify it under
8the terms of the GNU Affero General Public License as published by the Free
9Software Foundation, either version 3 of the License, or (at your option) any
10later version.
11
12This program is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
15
16You should have received a copy of the GNU Affero General Public License along
17with this program. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20//! Privacy-Enhanced Mail (PEM) encoding and certificate parsing utilities.
21
22#[allow(
23 unused_imports,
24 clippy::wildcard_imports,
25 reason = "Standard workspace crate prelude"
26)]
27pub(crate) use ctb_utilities::*;
28
29#[expect(
30 clippy::uninlined_format_args,
31 reason = "Much more readable in this case"
32)]
33pub fn ed25519_base64_to_pem(ed25519: &str) -> String {
34 // From my brief reading, it seems that this prefix is ASN.1 notation indicating that it is an Ed25519 key, encoded using DER, and then encoded using base64. FIXME: It would probably be nice to generate this some way that is clear what it actually is, rather than an unreadable string.
35 let prefix = "MCowBQYDK2VwAyEA";
36 format!(
37 "-----BEGIN PUBLIC KEY-----\n{}{}\n-----END PUBLIC KEY-----\n",
38 prefix, ed25519
39 )
40}
41
42#[cfg(test)]
43#[allow(
44 clippy::panic,
45 clippy::expect_used,
46 clippy::unwrap_used,
47 clippy::unwrap_in_result,
48 clippy::panic_in_result_fn,
49 clippy::indexing_slicing,
50 clippy::arithmetic_side_effects,
51 reason = "Standard repository test boilerplate"
52)]
53mod tests {}