rust/base64: upgrade crate to latest

base64 crate is updated to the latest version 0.22.1. This came with
several API changes which are applied to the code. The old calls have
been replaced with the newer calls.

This was done following the availability of better fns to directly
decode into slices/vectors as needed and also that previous version was
too old.
Along with this change, update the Cargo.lock.in to reflect all changes
in the package versions.

Task 7219
pull/11732/head
Shivani Bhardwaj 2 months ago committed by Victor Julien
parent 599a451e44
commit e93743a094

@ -114,9 +114,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]]
name = "base64"
version = "0.13.1"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
[[package]]
name = "bendy"

@ -58,7 +58,7 @@ sha1 = "~0.10.5"
md-5 = "~0.10.1"
regex = "~1.5.5"
lazy_static = "~1.4.0"
base64 = "~0.13.0"
base64 = "~0.22.1"
bendy = { version = "~0.3.3", default-features = false }
asn1-rs = { version = "~0.6.1" }
ldap-parser = { version = "~0.4.0" }

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Open Information Security Foundation
/* Copyright (C) 2021-2024 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
@ -17,6 +17,7 @@
use std::os::raw::c_uchar;
use libc::c_ulong;
use base64::{Engine, engine::general_purpose::STANDARD};
#[repr(C)]
#[allow(non_camel_case_types)]
@ -42,7 +43,7 @@ pub unsafe extern "C" fn Base64Encode(
return Base64ReturnCode::SC_BASE64_INVALID_ARG;
}
let input = std::slice::from_raw_parts(input, input_len as usize);
let encoded = base64::encode(input);
let encoded = STANDARD.encode(input);
if encoded.len() + 1 > *output_len as usize {
return Base64ReturnCode::SC_BASE64_OVERFLOW;
}

@ -1,4 +1,4 @@
/* Copyright (C) 2020 Open Information Security Foundation
/* Copyright (C) 2020-2024 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
@ -24,6 +24,7 @@ use crate::detect::uint::{detect_match_uint, DetectUintData};
use std::ffi::CStr;
use std::str::FromStr;
use std::rc::Rc;
use base64::{Engine, engine::general_purpose::STANDARD};
fn http2_tx_has_frametype(
tx: &mut HTTP2Transaction, direction: Direction, value: u8,
@ -957,7 +958,7 @@ pub unsafe extern "C" fn rs_http2_tx_set_uri(
}
fn http2_tx_set_settings(state: &mut HTTP2State, input: &[u8]) {
match base64::decode(input) {
match STANDARD.decode(input) {
Ok(dec) => {
if dec.len() % 6 != 0 {
state.set_event(HTTP2Event::InvalidHTTP1Settings);

@ -32,6 +32,7 @@ use nom7::{Err, IResult};
use std::fmt;
use std::str::FromStr;
use std::rc::Rc;
use base64::{Engine, engine::general_purpose::STANDARD_NO_PAD};
#[repr(u8)]
#[derive(Clone, Copy, PartialEq, Eq, FromPrimitive, Debug)]
@ -762,7 +763,7 @@ pub fn http2_parse_frame_settings(i: &[u8]) -> IResult<&[u8], Vec<HTTP2FrameSett
pub fn doh_extract_request(i: &[u8]) -> IResult<&[u8], Vec<u8>> {
let (i, _) = tag("/dns-query?dns=")(i)?;
match base64::decode(i) {
match STANDARD_NO_PAD.decode(i) {
Ok(dec) => {
// i is unused
return Ok((i, dec));

@ -24,6 +24,7 @@ use std::collections::TryReserveError;
use std::ffi::CStr;
use std::os::raw::c_char;
use std::str::Utf8Error;
use base64::{Engine, engine::general_purpose::STANDARD};
const INIT_SIZE: usize = 4096;
@ -807,7 +808,7 @@ impl JsonBuilder {
if self.buf.capacity() < self.buf.len() + encoded_len {
self.buf.try_reserve(encoded_len)?;
}
base64::encode_config_buf(val, base64::STANDARD, &mut self.buf);
STANDARD.encode_string(val, &mut self.buf);
Ok(self)
}
}

Loading…
Cancel
Save