From d2293df0112cb98e7b5e93dcb05cf8dbf1b05b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?= Date: Tue, 10 Feb 2026 21:23:11 +0100 Subject: [PATCH] base64: be a tolerant reader --- src/apply.rs | 5 +++-- src/lib.rs | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/apply.rs b/src/apply.rs index 52fc5a9..3d8e93a 100644 --- a/src/apply.rs +++ b/src/apply.rs @@ -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?, diff --git a/src/lib.rs b/src/lib.rs index 586e251..dd31d3d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,3 +81,8 @@ impl Config { self.files.iter().find(|f| f.path == path) } } + +pub fn base64_decode(s: &str) -> Result, base64::DecodeError> { + use base64::{prelude::BASE64_STANDARD_NO_PAD as B64, Engine}; + B64.decode(s.trim_end_matches('=')) +}