Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/data-model/src/tokens.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2024 New Vector Ltd.
// Copyright 2024, 2025 New Vector Ltd.
// Copyright 2021-2024 The Matrix.org Foundation C.I.C.
//
// SPDX-License-Identifier: AGPL-3.0-only
// Please see LICENSE in the repository root for full details.

use base64ct::{Base64Url, Encoding};
use base64ct::{Base64UrlUnpadded, Encoding};
use chrono::{DateTime, Utc};
use crc::{CRC_32_ISO_HDLC, Crc};
use mas_iana::oauth::OAuthTokenTypeHint;
Expand Down Expand Up @@ -353,7 +353,7 @@ impl PartialEq<OAuthTokenTypeHint> for TokenType {
/// We won't bother to decode them fully, but we can check to see if the first
/// constraint is the `location` constraint.
fn is_likely_synapse_macaroon(token: &str) -> bool {
let Ok(decoded) = Base64Url::decode_vec(token) else {
let Ok(decoded) = Base64UrlUnpadded::decode_vec(token) else {
return false;
};
decoded.get(4..13) == Some(b"location ")
Expand Down Expand Up @@ -443,8 +443,8 @@ mod tests {
"MDAxYmxvY2F0aW9uIGxpYnJlcHVzaC5uZXQKMDAx"
));

// Whilst this is a macaroon, it's not a Synapse macaroon
assert!(!is_likely_synapse_macaroon(
// This is a valid macaroon (even though Synapse did not generate this one)
assert!(is_likely_synapse_macaroon(
"MDAxY2xvY2F0aW9uIGh0dHA6Ly9teWJhbmsvCjAwMjZpZGVudGlmaWVyIHdlIHVzZWQgb3VyIHNlY3JldCBrZXkKMDAyZnNpZ25hdHVyZSDj2eApCFJsTAA5rhURQRXZf91ovyujebNCqvD2F9BVLwo"
));

Expand Down
Loading