Upgrade base64 to 0.21
This commit is contained in:
parent
4ef30d5652
commit
fe5077b1a5
@ -7,7 +7,7 @@ resolver = "2"
|
|||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
assert_matches = "1.5.0"
|
assert_matches = "1.5.0"
|
||||||
assign = "1.1.1"
|
assign = "1.1.1"
|
||||||
base64 = "0.20.0"
|
base64 = "0.21.0"
|
||||||
criterion = "0.4.0"
|
criterion = "0.4.0"
|
||||||
http = "0.2.8"
|
http = "0.2.8"
|
||||||
js_int = "0.2.2"
|
js_int = "0.2.2"
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
use std::{fmt, marker::PhantomData};
|
use std::{fmt, marker::PhantomData};
|
||||||
|
|
||||||
use base64::engine::fast_portable::{self, FastPortable, FastPortableConfig};
|
use base64::{
|
||||||
|
engine::{general_purpose, GeneralPurpose, GeneralPurposeConfig},
|
||||||
|
Engine,
|
||||||
|
};
|
||||||
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
/// A wrapper around `B` (usually `Vec<u8>`) that (de)serializes from / to a base64 string.
|
/// A wrapper around `B` (usually `Vec<u8>`) that (de)serializes from / to a base64 string.
|
||||||
@ -54,8 +57,9 @@ impl Base64Config for UrlSafe {
|
|||||||
|
|
||||||
impl<C: Base64Config, B> Base64<C, B> {
|
impl<C: Base64Config, B> Base64<C, B> {
|
||||||
// See https://github.com/matrix-org/matrix-spec/issues/838
|
// See https://github.com/matrix-org/matrix-spec/issues/838
|
||||||
const CONFIG: FastPortableConfig = fast_portable::NO_PAD.with_decode_allow_trailing_bits(true);
|
const CONFIG: GeneralPurposeConfig =
|
||||||
const ENGINE: FastPortable = FastPortable::from(&C::CONF.0, Self::CONFIG);
|
general_purpose::NO_PAD.with_decode_allow_trailing_bits(true);
|
||||||
|
const ENGINE: GeneralPurpose = GeneralPurpose::new(&C::CONF.0, Self::CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: Base64Config, B: AsRef<[u8]>> Base64<C, B> {
|
impl<C: Base64Config, B: AsRef<[u8]>> Base64<C, B> {
|
||||||
@ -71,7 +75,7 @@ impl<C: Base64Config, B: AsRef<[u8]>> Base64<C, B> {
|
|||||||
|
|
||||||
/// Encode the bytes contained in this `Base64` instance to unpadded base64.
|
/// Encode the bytes contained in this `Base64` instance to unpadded base64.
|
||||||
pub fn encode(&self) -> String {
|
pub fn encode(&self) -> String {
|
||||||
base64::encode_engine(self.as_bytes(), &Self::ENGINE)
|
Self::ENGINE.encode(self.as_bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +94,7 @@ impl<C: Base64Config> Base64<C> {
|
|||||||
|
|
||||||
/// Parse some base64-encoded data to create a `Base64` instance.
|
/// Parse some base64-encoded data to create a `Base64` instance.
|
||||||
pub fn parse(encoded: impl AsRef<[u8]>) -> Result<Self, Base64DecodeError> {
|
pub fn parse(encoded: impl AsRef<[u8]>) -> Result<Self, Base64DecodeError> {
|
||||||
base64::decode_engine(encoded, &Self::ENGINE).map(Self::new).map_err(Base64DecodeError)
|
Self::ENGINE.decode(encoded).map(Self::new).map_err(Base64DecodeError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ use std::{
|
|||||||
mem,
|
mem,
|
||||||
};
|
};
|
||||||
|
|
||||||
use base64::{alphabet, encode_engine};
|
use base64::{alphabet, Engine};
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
canonical_json::{redact, JsonType},
|
canonical_json::{redact, JsonType},
|
||||||
serde::{base64::Standard, Base64},
|
serde::{base64::Standard, Base64},
|
||||||
@ -338,12 +338,12 @@ pub fn reference_hash(
|
|||||||
// Room versions higher than version 3 are url safe base64 encoded
|
// Room versions higher than version 3 are url safe base64 encoded
|
||||||
_ => alphabet::URL_SAFE,
|
_ => alphabet::URL_SAFE,
|
||||||
};
|
};
|
||||||
let base64_engine = base64::engine::fast_portable::FastPortable::from(
|
let base64_engine = base64::engine::GeneralPurpose::new(
|
||||||
&base64_alphabet,
|
&base64_alphabet,
|
||||||
base64::engine::fast_portable::NO_PAD,
|
base64::engine::general_purpose::NO_PAD,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(encode_engine(hash, &base64_engine))
|
Ok(base64_engine.encode(hash))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hashes and signs an event and adds the hash and signature to objects under the keys `hashes` and
|
/// Hashes and signs an event and adds the hash and signature to objects under the keys `hashes` and
|
||||||
|
Loading…
x
Reference in New Issue
Block a user