Skip to content

Commit

Permalink
Add tool to generate event UIDs and update README
Browse files Browse the repository at this point in the history
According to the iCalendar (IETF) RFC 5545, the UID for each event
must be "globally unique".  In this context, that means that the
identifier must not collide with any other identifier for any other
calendar event across all calendars, ever.

The way we were suggesting that people generate these, by calling out
to `date`, unfortunately falls a bit short of being able to assure
this.

Let's instead add a small tool to generate sufficiently-long
randomly-generated identifiers to make it easy for people to do the
right thing here for new events.
  • Loading branch information
traviscross committed Nov 13, 2024
1 parent 7cec3fa commit 6b294a2
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 2 deletions.
39 changes: 39 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "calendar"
version = "0.0.0"
edition = "2021"
license = "MIT OR Apache-2.0"
publish = false

[dependencies]
getrandom = { version = "0.2.15", default-features = false }
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,15 @@ to update `last_modified_on`. Some clients use `last_modified_on` to decide whet
update to an event or recurrence or not. To ensure the client will publish the event, set
`last_modified_on` to a value in the future (a few days past the current date should be enough).

On Linux, you can get the current time in the right format in UTC with the command
`TZ=UTC date -u +"%Y-%m-%dT%H:%M:%S.%2NZ"`.
## How do I generate a UID for a new event?

To generate a UID, run:

```sh
cargo run --bin generate-ical-uid
```

Use the printed value as the `uid` for the event.

## How do I remove an event?
If the event isn't recurring, then you don't need to remove it, it'll just stay in the calendar
Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use_small_heuristics = "Max"
25 changes: 25 additions & 0 deletions src/bin/generate-ical-uid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! Generate a UID for an RFC 5545 iCalendar event.
//!
//! The iCalender (IETF) RFC 5545 requires, in section 3.8.4.7, that
//! the `UID` be a:
//!
//! > ...persistent, globally unique identifier for the calendar
//! > component.
//!
//! In this context, "globally unique" means that the identifier must
//! not collide with any other identifier for any other calendar event
//! across all calendars, ever.
//!
//! To achieve this, we'll generate a hexidecimal encoding of 160
//! randomly-generated bits.
use getrandom::getrandom;

const UID_LEN: usize = 20;

fn main() {
let mut xs = [0u8; UID_LEN];
getrandom(&mut xs).unwrap();
xs.iter().for_each(|x| print!("{x:02x}"));
println!();
}

0 comments on commit 6b294a2

Please sign in to comment.