Skip to content

Commit

Permalink
Update comments for new returns on padded decodes, and link from unpa…
Browse files Browse the repository at this point in the history
…dded capacity fns
  • Loading branch information
rogusdev committed Dec 27, 2023
1 parent 81e79e1 commit 9c1308c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/base32/alphabet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ impl Alphabet32Padded {
}

/// Pass decoder array to [`decode`](super::decode()), and remove padding as needed
///
/// Also returns [`DecodeError`] if input is an invalid length for padding (i.e. not a multiple of 8)
#[inline]
pub fn decode(&self, a: &[u8]) -> Result<Vec<u8>, DecodeError> {
if a.len() % WIDTH_ENC != 0 {
Expand All @@ -239,6 +241,8 @@ impl Alphabet32Padded {
}

/// Pass decoder array to [`decode_into`](super::decode_into()), and remove padding as needed
///
/// Also returns [`DecodeError`] if input is an invalid length for padding (i.e. not a multiple of 8)
#[inline]
pub fn decode_into(&self, a: &[u8], b: &mut Vec<u8>) -> Result<(), DecodeError> {
if a.len() % WIDTH_ENC != 0 {
Expand All @@ -249,6 +253,8 @@ impl Alphabet32Padded {
}

/// Pass string as bytes and decoder array to [`decode`](super::decode()), and remove padding as needed
///
/// Also returns [`DecodeError`] if input is an invalid length for padding (i.e. not a multiple of 8)
#[inline]
pub fn decode_str(&self, a: impl AsRef<str>) -> Result<Vec<u8>, DecodeError> {
let a = a.as_ref().as_bytes();
Expand Down
2 changes: 2 additions & 0 deletions src/base32/decode_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::shared::{bits_or_err_u8, DecodeError};
use super::alphabet::{WIDTH_DEC, WIDTH_ENC};

/// Capacity needed in dest `Vec<u8>` to decode this byte array -- without padding!
///
/// Also see padded [`capacity_decode`](super::Alphabet32Padded::capacity_decode())
#[inline]
pub const fn capacity_decode(a: &[u8]) -> usize {
a.len() * WIDTH_DEC / WIDTH_ENC
Expand Down
2 changes: 2 additions & 0 deletions src/base32/encode_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const U8_MASK_MID_2: u8 = 0b01111100;
const U8_MASK_MID_1: u8 = 0b00111110;

/// Capacity needed in dest `Vec<u8>` to encode this byte array -- without padding!
///
/// Also see padded [`capacity_encode`](super::Alphabet32Padded::capacity_encode())
#[inline]
pub const fn capacity_encode(a: &[u8]) -> usize {
// https://stackoverflow.com/questions/23636240/how-do-i-predict-the-required-size-of-a-base32-decode-output
Expand Down
6 changes: 6 additions & 0 deletions src/base64/alphabet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ impl Alphabet64Padded {
}

/// Pass decoder array to [`decode`](super::decode()), and remove padding as needed
///
/// Also returns [`DecodeError`] if input is an invalid length for padding (i.e. not a multiple of 4)
#[inline]
pub fn decode(&self, a: &[u8]) -> Result<Vec<u8>, DecodeError> {
if a.len() % WIDTH_ENC != 0 {
Expand All @@ -190,6 +192,8 @@ impl Alphabet64Padded {
}

/// Pass decoder array to [`decode_into`](super::decode_into()), and remove padding as needed
///
/// Also returns [`DecodeError`] if input is an invalid length for padding (i.e. not a multiple of 4)
#[inline]
pub fn decode_into(&self, a: &[u8], b: &mut Vec<u8>) -> Result<(), DecodeError> {
if a.len() % WIDTH_ENC != 0 {
Expand All @@ -200,6 +204,8 @@ impl Alphabet64Padded {
}

/// Pass string as bytes and decoder array to [`decode`](super::decode()), and remove padding as needed
///
/// Also returns [`DecodeError`] if input is an invalid length for padding (i.e. not a multiple of 4)
#[inline]
pub fn decode_str(&self, a: impl AsRef<str>) -> Result<Vec<u8>, DecodeError> {
let a = a.as_ref().as_bytes();
Expand Down
2 changes: 2 additions & 0 deletions src/base64/decode_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::shared::{bits_or_err_u8, DecodeError};
use super::alphabet::{WIDTH_DEC, WIDTH_ENC};

/// Capacity needed in dest `Vec<u8>` to decode this byte array -- without padding!
///
/// Also see padded [`capacity_decode`](super::Alphabet64Padded::capacity_decode())
#[inline]
pub const fn capacity_decode(a: &[u8]) -> usize {
a.len() * WIDTH_DEC / WIDTH_ENC
Expand Down
2 changes: 2 additions & 0 deletions src/base64/encode_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::shared::*;
use super::alphabet::{BITS, WIDTH_DEC, WIDTH_ENC};

/// Capacity needed in dest `Vec<u8>` to encode this byte array -- without padding!
///
/// Also see padded [`capacity_encode`](super::Alphabet64Padded::capacity_encode())
#[inline]
pub const fn capacity_encode(a: &[u8]) -> usize {
// https://stackoverflow.com/questions/23636240/how-do-i-predict-the-required-size-of-a-base32-decode-output
Expand Down

0 comments on commit 9c1308c

Please sign in to comment.