From b08fb43134eee53ab544900ea168cac3f02efdf9 Mon Sep 17 00:00:00 2001 From: Arash Sahebolamri Date: Thu, 26 Oct 2023 15:49:35 -0700 Subject: [PATCH] Make `x509::Time` more useful --- .gitignore | 3 +- Cargo.lock | 1 + README.md | 3 +- ci.sh | 1 + mbedtls/Cargo.toml | 1 + mbedtls/src/x509/mod.rs | 86 +++++++++++++++++++++++++++++++++++++---- 6 files changed, 85 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 2e030bcb2..2dbbc93cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .cargo target/ -venv/ \ No newline at end of file +venv/ +.vscode \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 229635412..3a12768a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -494,6 +494,7 @@ dependencies = [ "cbc", "cc", "cfg-if 1.0.0", + "chrono", "futures", "hex", "hyper", diff --git a/README.md b/README.md index e5d1cf6f5..27e3a040d 100644 --- a/README.md +++ b/README.md @@ -78,8 +78,7 @@ crypto (or PKI) only library. * **time** Enable time support in mbedtls-sys. * *zlib* Enable zlib support in mbedtls-sys. * *async-rt* Enable async support for SSL. - -PRs adding new features are encouraged. +* *chrono* Enable [`chrono`](https://docs.rs/chrono/) support (e.g., implementation of conversion traits between `x509::Time` and `chrono` types) # mbedtls-sys-auto diff --git a/ci.sh b/ci.sh index 16217af0b..500177e09 100755 --- a/ci.sh +++ b/ci.sh @@ -53,6 +53,7 @@ case "$TRAVIS_RUST_VERSION" in if [ "$TARGET" != "x86_64-fortanix-unknown-sgx" ]; then cargo nextest run --test async_session --features=async-rt,ssl --target $TARGET cargo nextest run --test async_session --features=async-rt,ssl,legacy_protocols --target $TARGET + cargo nextest run chrono --features=chrono,ssl,x509 --target $TARGET # If zlib is installed, test the zlib feature if [ -n "$ZLIB_INSTALLED" ]; then diff --git a/mbedtls/Cargo.toml b/mbedtls/Cargo.toml index 2a2b36f53..30b3ef90e 100644 --- a/mbedtls/Cargo.toml +++ b/mbedtls/Cargo.toml @@ -31,6 +31,7 @@ cbc = { version = "0.1.2", optional = true } rc2 = { version = "0.8.1", optional = true } cfg-if = "1.0.0" tokio = { version = "1.16.1", optional = true } +chrono = { version = "0.4", optional = true } [target.x86_64-fortanix-unknown-sgx.dependencies] rs-libc = "0.2.0" diff --git a/mbedtls/src/x509/mod.rs b/mbedtls/src/x509/mod.rs index b027f3684..699bbbd86 100644 --- a/mbedtls/src/x509/mod.rs +++ b/mbedtls/src/x509/mod.rs @@ -196,19 +196,19 @@ impl Time { pub fn new(year: u16, month: u8, day: u8, hour: u8, minute: u8, second: u8) -> Option