events: Fix wrong base64 character set for k field in JsonWebKey
This commit is contained in:
parent
47cc004e06
commit
0dbeac8505
@ -6,7 +6,7 @@ use std::collections::BTreeMap;
|
|||||||
|
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_identifiers::MxcUri;
|
use ruma_identifiers::MxcUri;
|
||||||
use ruma_serde::Base64;
|
use ruma_serde::{base64::UrlSafe, Base64};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub mod aliases;
|
pub mod aliases;
|
||||||
@ -193,7 +193,7 @@ pub struct JsonWebKey {
|
|||||||
pub alg: String,
|
pub alg: String,
|
||||||
|
|
||||||
/// The key, encoded as url-safe unpadded base64.
|
/// The key, encoded as url-safe unpadded base64.
|
||||||
pub k: Base64,
|
pub k: Base64<UrlSafe>,
|
||||||
|
|
||||||
/// Extractable.
|
/// Extractable.
|
||||||
///
|
///
|
||||||
@ -225,7 +225,7 @@ pub struct JsonWebKeyInit {
|
|||||||
pub alg: String,
|
pub alg: String,
|
||||||
|
|
||||||
/// The key, encoded as url-safe unpadded base64.
|
/// The key, encoded as url-safe unpadded base64.
|
||||||
pub k: Base64,
|
pub k: Base64<UrlSafe>,
|
||||||
|
|
||||||
/// Extractable.
|
/// Extractable.
|
||||||
///
|
///
|
||||||
|
@ -2,15 +2,39 @@ use std::fmt;
|
|||||||
|
|
||||||
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
/// DOCS
|
/// A wrapper around `B` (usually `Vec<u8>`) that (de)serializes from / to a base64 string.
|
||||||
// generic?
|
///
|
||||||
|
/// The base64 character set (and miscellaneous other encoding / decoding options) can be customized
|
||||||
|
/// through the generic parameter `C`.
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct Base64<B = Vec<u8>> {
|
pub struct Base64<C = Standard, B = Vec<u8>> {
|
||||||
bytes: B,
|
bytes: B,
|
||||||
}
|
}
|
||||||
|
|
||||||
// See https://github.com/matrix-org/matrix-doc/issues/3211
|
pub trait Base64Config {
|
||||||
const BASE64_CONFIG: base64::Config = base64::STANDARD_NO_PAD.decode_allow_trailing_bits(true);
|
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 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> {
|
impl<B: AsRef<[u8]>> Base64<B> {
|
||||||
/// Create a `Base64` instance from raw bytes, to be base64-encoded in serialialization.
|
/// Create a `Base64` instance from raw bytes, to be base64-encoded in serialialization.
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
use serde_json::Value as JsonValue;
|
use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
mod base64;
|
pub mod base64;
|
||||||
mod buf;
|
mod buf;
|
||||||
pub mod can_be_empty;
|
pub mod can_be_empty;
|
||||||
mod canonical_json;
|
mod canonical_json;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user