// Copyright 2026 Thomas Zuyev

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod base64 {
    use base64::{Engine, prelude::BASE64_URL_SAFE_NO_PAD};

    pub use base64::DecodeSliceError;

    /// Encodes bytes using URL-safe base64 without padding
    /// (`RFC 4648 §5`, `-` and `_` alphabet).
    pub fn encode<T: AsRef<[u8]>>(input: T) -> String {
        BASE64_URL_SAFE_NO_PAD.encode(input)
    }

    /// Decodes URL-safe, unpadded base64 into the provided buffer.
    /// Fails if the input is invalid or the output buffer is too small.
    pub fn decode_slice<T: AsRef<[u8]>>(
        input: T,
        output: &mut [u8],
    ) -> Result<usize, DecodeSliceError> {
        BASE64_URL_SAFE_NO_PAD.decode_slice(input, output)
    }
}
