base64: be a tolerant reader

This commit is contained in:
Mikaël Cluseau
2026-02-10 21:23:11 +01:00
parent 723cecff1b
commit d2293df011
2 changed files with 8 additions and 2 deletions

View File

@ -3,6 +3,8 @@ use log::info;
use std::path::Path;
use tokio::fs;
use crate::base64_decode;
pub async fn files(files: &[crate::File], root: &str) -> Result<()> {
for file in files {
let path = chroot(root, &file.path);
@ -16,8 +18,7 @@ pub async fn files(files: &[crate::File], root: &str) -> Result<()> {
match &file.kind {
K::Content(content) => fs::write(path, content.as_bytes()).await?,
K::Content64(content) => {
use base64::prelude::{Engine as _, BASE64_STANDARD_NO_PAD as B64};
let content = B64.decode(content)?;
let content = base64_decode(content)?;
fs::write(path, content).await?
}
K::Dir(true) => fs::create_dir(path).await?,

View File

@ -81,3 +81,8 @@ impl Config {
self.files.iter().find(|f| f.path == path)
}
}
pub fn base64_decode(s: &str) -> Result<Vec<u8>, base64::DecodeError> {
use base64::{prelude::BASE64_STANDARD_NO_PAD as B64, Engine};
B64.decode(s.trim_end_matches('='))
}