summaryrefslogtreecommitdiff
path: root/src/channel/repo.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-19 01:51:30 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-21 00:49:05 -0400
commit379e97c2cb145bc3a495aa14746273d83b508214 (patch)
tree218bbe2572af9dd4b165ff05495d084dc0bd8905 /src/channel/repo.rs
parent98af8ff80da919a1126ba7c6afa65e6654b5ecde (diff)
Unicode normalization on input.
This normalizes the following values: * login names * passwords * channel names * message bodies, because why not The goal here is to have a canonical representation of these values, so that, for example, the service does not inadvertently host two channels whose names are semantically identical but differ in the specifics of how diacritics are encoded, or two users whose names are identical. Normalization is done on input from the wire, using Serde hooks, and when reading from the database. The `crate::nfc::String` type implements these normalizations (as well as normalizing whenever converted from a `std::string::String` generally). This change does not cover: * Trying to cope with passwords that were created as non-normalized strings, which are now non-verifiable as all the paths to verify passwords normalize the input. * Trying to ensure that non-normalized data in the database compares reasonably to normalized data. Fortunately, we don't _do_ very many string comparisons (I think only login names), so this isn't a huge deal at this stage. Login names will probably have to Get Fixed later on, when we figure out how to handle case folding for login name verification.
Diffstat (limited to 'src/channel/repo.rs')
-rw-r--r--src/channel/repo.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/channel/repo.rs b/src/channel/repo.rs
index 27d35f0..3353bfd 100644
--- a/src/channel/repo.rs
+++ b/src/channel/repo.rs
@@ -1,7 +1,7 @@
use sqlx::{sqlite::Sqlite, SqliteConnection, Transaction};
use crate::{
- channel::{Channel, History, Id},
+ channel::{Channel, History, Id, Name},
clock::DateTime,
event::{Instant, ResumePoint, Sequence},
};
@@ -19,7 +19,7 @@ impl<'c> Provider for Transaction<'c, Sqlite> {
pub struct Channels<'t>(&'t mut SqliteConnection);
impl<'c> Channels<'c> {
- pub async fn create(&mut self, name: &str, created: &Instant) -> Result<History, sqlx::Error> {
+ pub async fn create(&mut self, name: &Name, created: &Instant) -> Result<History, sqlx::Error> {
let id = Id::generate();
let channel = sqlx::query!(
r#"
@@ -28,7 +28,7 @@ impl<'c> Channels<'c> {
values ($1, $2, $3, $4)
returning
id as "id: Id",
- name as "name!", -- known non-null as we just set it
+ name as "name!: Name", -- known non-null as we just set it
created_at as "created_at: DateTime",
created_sequence as "created_sequence: Sequence"
"#,
@@ -57,7 +57,7 @@ impl<'c> Channels<'c> {
r#"
select
id as "id: Id",
- channel.name,
+ channel.name as "name: Name",
channel.created_at as "created_at: DateTime",
channel.created_sequence as "created_sequence: Sequence",
deleted.deleted_at as "deleted_at?: DateTime",
@@ -89,7 +89,7 @@ impl<'c> Channels<'c> {
r#"
select
id as "id: Id",
- channel.name,
+ channel.name as "name: Name",
channel.created_at as "created_at: DateTime",
channel.created_sequence as "created_sequence: Sequence",
deleted.deleted_at as "deleted_at: DateTime",
@@ -125,7 +125,7 @@ impl<'c> Channels<'c> {
r#"
select
id as "id: Id",
- channel.name,
+ channel.name as "name: Name",
channel.created_at as "created_at: DateTime",
channel.created_sequence as "created_sequence: Sequence",
deleted.deleted_at as "deleted_at: DateTime",
@@ -235,7 +235,7 @@ impl<'c> Channels<'c> {
r#"
select
channel.id as "id: Id",
- channel.name,
+ channel.name as "name: Name",
channel.created_at as "created_at: DateTime",
channel.created_sequence as "created_sequence: Sequence",
deleted.deleted_at as "deleted_at?: DateTime",