summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyborus <cyborus@cyborus.xyz>2024-05-27 19:09:51 +0200
committerCyborus <cyborus@cyborus.xyz>2024-05-27 19:09:51 +0200
commitdc96dd55496db20187bf0d01b3dd88cd72165a0d (patch)
tree2603a7a68090f10a4ca3ecbc751f817c7747e025
parentfix follower account email (diff)
downloadforgejo-api-dc96dd55496db20187bf0d01b3dd88cd72165a0d.tar.xz
forgejo-api-dc96dd55496db20187bf0d01b3dd88cd72165a0d.zip
fix basic auth base64 encoding length calculation
-rw-r--r--src/lib.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index a87a696..d9b877e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -99,11 +99,13 @@ impl Forgejo {
password,
mfa,
} => {
- let len = (((username.len() + password.len() + 1)
+ let unencoded_len = username.len() + password.len() + 1;
+ let unpadded_len = unencoded_len
.checked_mul(4)
- .ok_or(ForgejoError::AuthTooLong)?)
- / 3)
- + 1;
+ .ok_or(ForgejoError::AuthTooLong)?
+ .div_ceil(3);
+ // round up to next multiple of 4, to account for padding
+ let len = unpadded_len.div_ceil(4) * 4;
let mut bytes = vec![0; len];
// panic safety: len cannot be zero