Skip to content

Commit

Permalink
fix safety comment, remove chrono dep
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Dec 19, 2024
1 parent d1ef225 commit 91ac57e
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 25 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ base64-simd = "0.8.0"
blake3 = "1.5.5"
bubble-bath = "0.2.1"
bytes = "1.9.0"
chrono = { version = "0.4.39", default-features = false }
clap = { version = "4.5.23", features = ["derive", "wrap_help"] }
color-eyre = "0.6.3"
colored_json = "5.0.0"
Expand Down
1 change: 0 additions & 1 deletion kitsune/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ axum-extra.workspace = true
axum-flash.workspace = true
blowocking.workspace = true
bytes.workspace = true
chrono.workspace = true
clap.workspace = true
color-eyre.workspace = true
cursiv.workspace = true
Expand Down
19 changes: 0 additions & 19 deletions kitsune/src/oauth2/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use axum::response::{Html, IntoResponse, Redirect, Response};
use chrono::Utc;
use diesel_async::RunQueryDsl;
use iso8601_timestamp::Timestamp;
use kitsune_db::{
Expand Down Expand Up @@ -32,24 +31,6 @@ pub use self::{endpoint::OAuthEndpoint, solicitor::OAuthOwnerSolicitor};
const SHOW_TOKEN_URI: &str = "urn:ietf:wg:oauth:2.0:oob";
static AUTH_TOKEN_VALID_DURATION: Duration = Duration::minutes(10);

#[inline]
fn timestamp_to_chrono(ts: iso8601_timestamp::Timestamp) -> chrono::DateTime<Utc> {
let secs = ts
.duration_since(iso8601_timestamp::Timestamp::UNIX_EPOCH)
.whole_seconds();

chrono::DateTime::from_timestamp(secs, ts.nanosecond()).unwrap()
}

#[inline]
fn chrono_to_timestamp(ts: chrono::DateTime<Utc>) -> iso8601_timestamp::Timestamp {
time::OffsetDateTime::from_unix_timestamp(ts.timestamp())
.unwrap()
.replace_nanosecond(ts.timestamp_subsec_nanos())
.unwrap()
.into()
}

#[derive(AsRefStr, Clone, Copy, Debug, EnumIter, EnumMessage, EnumString, Serialize)]
#[strum(serialize_all = "lowercase")]
pub enum OAuthScope {
Expand Down
5 changes: 2 additions & 3 deletions lib/komainu/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ impl BasicAuth {

String::from_utf8_unchecked(buffer)
};

let delimiter_pos = memchr(b':', buffer.as_bytes())?;

Some(Self {
Expand All @@ -117,7 +116,7 @@ impl BasicAuth {
#[inline]
#[must_use]
pub fn username(&self) -> &str {
// SAFETY: The delimiter was previously found via `str::find`, so the index is guaranteed to be within boundaries
// SAFETY: The delimiter was previously found via `memchr`, so the index is guaranteed to be within boundaries
#[allow(unsafe_code)]
unsafe {
self.buffer.get_unchecked(..self.delimiter_pos)
Expand All @@ -127,7 +126,7 @@ impl BasicAuth {
#[inline]
#[must_use]
pub fn password(&self) -> &str {
// SAFETY: The delimiter was previously found via `str::find`, so the index is guaranteed to be within boundaries
// SAFETY: The delimiter was previously found via `memchr`, so the index is guaranteed to be within boundaries
#[allow(unsafe_code)]
unsafe {
self.buffer.get_unchecked((self.delimiter_pos + 1)..)
Expand Down

0 comments on commit 91ac57e

Please sign in to comment.