events: Fix wrong base64 character set for k field in JsonWebKey

This commit is contained in:
Jonas Platte 2022-01-23 13:48:42 +01:00
parent 47cc004e06
commit 0dbeac8505
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
3 changed files with 33 additions and 9 deletions

View File

@ -6,7 +6,7 @@ use std::collections::BTreeMap;
use js_int::UInt;
use ruma_identifiers::MxcUri;
use ruma_serde::Base64;
use ruma_serde::{base64::UrlSafe, Base64};
use serde::{Deserialize, Serialize};
pub mod aliases;
@ -193,7 +193,7 @@ pub struct JsonWebKey {
pub alg: String,
/// The key, encoded as url-safe unpadded base64.
pub k: Base64,
pub k: Base64<UrlSafe>,
/// Extractable.
///
@ -225,7 +225,7 @@ pub struct JsonWebKeyInit {
pub alg: String,
/// The key, encoded as url-safe unpadded base64.
pub k: Base64,
pub k: Base64<UrlSafe>,
/// Extractable.
///

View File

@ -2,15 +2,39 @@ use std::fmt;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
/// DOCS
// generic?
/// A wrapper around `B` (usually `Vec<u8>`) that (de)serializes from / to a base64 string.
///
/// The base64 character set (and miscellaneous other encoding / decoding options) can be customized
/// through the generic parameter `C`.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Base64<B = Vec<u8>> {
pub struct Base64<C = Standard, B = Vec<u8>> {
bytes: B,
}
pub trait Base64Config {
const CONF: base64::Config;
}
/// Standard base64 character set without padding.
///
/// Allows trailing bits in decoding for maximum compatibility.
#[non_exhaustive]
pub struct Standard;
impl Base64Config for Standard {
// See https://github.com/matrix-org/matrix-doc/issues/3211
const BASE64_CONFIG: base64::Config = base64::STANDARD_NO_PAD.decode_allow_trailing_bits(true);
const CONF: base64::Config = base64::STANDARD_NO_PAD.decode_allow_trailing_bits(true);
}
/// Url-safe base64 character set without padding.
///
/// Allows trailing bits in decoding for maximum compatibility.
#[non_exhaustive]
pub struct UrlSafe;
impl Base64Config for UrlSafe {
const CONF: base64::Config = base64::URL_SAFE_NO_PAD.decode_allow_trailing_bits(true);
}
impl<B: AsRef<[u8]>> Base64<B> {
/// Create a `Base64` instance from raw bytes, to be base64-encoded in serialialization.

View File

@ -6,7 +6,7 @@
use serde_json::Value as JsonValue;
mod base64;
pub mod base64;
mod buf;
pub mod can_be_empty;
mod canonical_json;