From a13a0c2370f395abac5a1101d24c13a8d4554719 Mon Sep 17 00:00:00 2001 From: Christopher Rabotin Date: Tue, 23 Apr 2024 20:50:10 -0600 Subject: [PATCH 1/3] Removed der Closes #230 --- Cargo.toml | 4 +- README.md | 1 + src/asn1der.rs | 154 ------------------------------------------------- src/lib.rs | 3 - 4 files changed, 2 insertions(+), 160 deletions(-) delete mode 100644 src/asn1der.rs diff --git a/Cargo.toml b/Cargo.toml index 352b238..8137318 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ name = "hifitime" [dependencies] serde = { version = "1.0.155", optional = true } serde_derive = { version = "1.0.155", optional = true } -der = { version = "0.7.8", features = ["derive", "real"], optional = true } pyo3 = { version = "0.21.1", features = [ "extension-module", "inventory", @@ -72,8 +71,7 @@ iai = "0.1" [features] default = ["std"] std = ["serde", "serde_derive", "web-time"] -asn1der = ["der"] -python = ["std", "asn1der", "pyo3", "ut1"] +python = ["std", "pyo3", "ut1"] ut1 = ["std", "reqwest", "tabled", "openssl"] [[bench]] diff --git a/README.md b/README.md index 7879da9..70a411d 100644 --- a/README.md +++ b/README.md @@ -314,6 +314,7 @@ In order to provide full interoperability with NAIF, hifitime uses the NAIF algo + Minimum Support Rust Version (MSRV) bumped to 1.77.0 + Major refactoring of the code for ease of maintenance and removal of deprecrated functions from 3.x + Centralization of all time scale conversions into the `to_time_scale` function -- huge effort by [@gwbres](https://github.com/gwbres) ++ Removed `der` encoding/decoding for Epoch and Duration. ## 3.9.0 diff --git a/src/asn1der.rs b/src/asn1der.rs deleted file mode 100644 index 462ef6d..0000000 --- a/src/asn1der.rs +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Hifitime, part of the Nyx Space tools - * Copyright (C) 2023 Christopher Rabotin et al. (cf. https://github.com/nyx-space/hifitime/graphs/contributors) - * This Source Code Form is subject to the terms of the Apache - * v. 2.0. If a copy of the Apache License was not distributed with this - * file, You can obtain one at https://www.apache.org/licenses/LICENSE-2.0. - * - * Documentation: https://nyxspace.com/ - */ - -use crate::Unit; - -use super::{Duration, Epoch, TimeScale}; - -use der::{Decode, Encode, Reader, Writer}; - -/// A duration is encoded with the centuries first followed by the nanoseconds. -impl Encode for Duration { - fn encoded_len(&self) -> der::Result { - let (centuries, nanoseconds) = self.to_parts(); - centuries.encoded_len()? + nanoseconds.encoded_len()? - } - - fn encode(&self, encoder: &mut impl Writer) -> der::Result<()> { - let (centuries, nanoseconds) = self.to_parts(); - centuries.encode(encoder)?; - nanoseconds.encode(encoder) - } -} - -impl<'a> Decode<'a> for Duration { - fn decode>(decoder: &mut R) -> der::Result { - let centuries = decoder.decode()?; - let nanoseconds = decoder.decode()?; - Ok(Duration::from_parts(centuries, nanoseconds)) - } -} - -/// An Epoch is encoded with time system first followed by the duration structure. -impl Encode for Epoch { - fn encoded_len(&self) -> der::Result { - let ts: u8 = self.time_scale.into(); - ts.encoded_len()? + self.duration.encoded_len()? - } - - fn encode(&self, encoder: &mut impl Writer) -> der::Result<()> { - let ts: u8 = self.time_scale.into(); - - ts.encode(encoder)?; - self.duration.encode(encoder) - } -} - -impl<'a> Decode<'a> for Epoch { - fn decode>(decoder: &mut R) -> der::Result { - let ts: u8 = decoder.decode()?; - let duration = decoder.decode()?; - let time_scale: TimeScale = TimeScale::from(ts); - Ok(match time_scale { - TimeScale::TAI => Self::from_tai_duration(duration), - TimeScale::TT => Self::from_tt_duration(duration), - TimeScale::ET => Self::from_et_duration(duration), - TimeScale::TDB => Self::from_tdb_duration(duration), - TimeScale::UTC => Self::from_utc_duration(duration), - TimeScale::GPST => Self::from_gpst_duration(duration), - TimeScale::QZSST => Self::from_qzsst_duration(duration), - TimeScale::GST => Self::from_gst_duration(duration), - TimeScale::BDT => Self::from_bdt_duration(duration), - }) - } -} - -/// An Epoch is encoded with time system first followed by the duration structure. -impl Encode for Unit { - fn encoded_len(&self) -> der::Result { - let converted: u8 = self.into(); - converted.encoded_len() - } - - fn encode(&self, encoder: &mut impl Writer) -> der::Result<()> { - let converted: u8 = self.into(); - converted.encode(encoder) - } -} - -impl<'a> Decode<'a> for Unit { - fn decode>(decoder: &mut R) -> der::Result { - let converted: u8 = decoder.decode()?; - Ok(Self::from(converted)) - } -} - -// Testing the encoding and decoding of an Epoch inherently also tests the encoding and decoding of a Duration -#[test] -fn test_encdec() { - for ts_u8 in 0..=8 { - let ts: TimeScale = ts_u8.into(); - - let epoch = if ts == TimeScale::UTC { - Epoch::from_gregorian_utc_hms(2022, 9, 6, 23, 24, 29) - } else { - Epoch::from_gregorian_hms(2022, 9, 6, 23, 24, 29, ts) - }; - - let duration = match ts { - TimeScale::TAI => epoch.to_tai_duration(), - TimeScale::ET => epoch.to_et_duration(), - TimeScale::TT => epoch.to_tt_duration(), - TimeScale::TDB => epoch.to_tdb_duration(), - TimeScale::UTC => epoch.to_utc_duration(), - TimeScale::GPST => epoch.to_gpst_duration(), - TimeScale::GST => epoch.to_gst_duration(), - TimeScale::BDT => epoch.to_bdt_duration(), - TimeScale::QZSST => epoch.to_qzsst_duration(), - }; - - let e_dur = epoch.duration; - - assert_eq!(e_dur, duration, "{ts:?}"); - - // Create a buffer - let mut buf = [0_u8; 16]; - // Encode - epoch.encode_to_slice(&mut buf).unwrap(); - // Decode - let encdec_epoch = Epoch::from_der(&buf).unwrap(); - // Check that the duration in J1900 TAI is the same - assert_eq!( - encdec_epoch.duration, epoch.duration, - "Decoded epoch incorrect ({ts:?}):\ngot: {encdec_epoch}\nexp: {epoch}", - ); - // Check that the time scale used is preserved - assert_eq!( - encdec_epoch.time_scale, ts, - "Decoded time system incorrect {ts:?}", - ); - } - - for unit_u8 in 0..=7 { - let unit: Unit = unit_u8.into(); - - // Create a buffer - let mut buf = [0_u8; 3]; - // Encode - unit.encode_to_slice(&mut buf).unwrap(); - // Decode - let encdec_unit = Unit::from_der(&buf).unwrap(); - - assert_eq!( - encdec_unit, unit, - "Decoded epoch incorrect ({unit:?}):\ngot: {encdec_unit:?}\nexp: {unit:?}", - ); - } -} diff --git a/src/lib.rs b/src/lib.rs index 8ba346e..ab0e453 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -105,9 +105,6 @@ pub mod prelude { }; } -#[cfg(feature = "asn1der")] -pub mod asn1der; - #[cfg(feature = "python")] pub mod python; From e18f84520afa2c081964a5a51ea2bdfebb5c4ea4 Mon Sep 17 00:00:00 2001 From: Christopher Rabotin Date: Tue, 23 Apr 2024 21:24:21 -0600 Subject: [PATCH 2/3] Remove asn1der from test --- .github/workflows/tests.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cd53182..5f64dca 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -50,9 +50,6 @@ jobs: - name: Test (default features) run: cargo test - - name: Test (ASN1) - run: cargo test --features asn1der - - name: Test (UT1) run: cargo test --features ut1 From 8ede0d8bc9581b37099c1455ae60745d01d7d155 Mon Sep 17 00:00:00 2001 From: Christopher Rabotin Date: Tue, 23 Apr 2024 21:29:02 -0600 Subject: [PATCH 3/3] Idem --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5f64dca..072df79 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -117,8 +117,8 @@ jobs: - name: Generate coverage report run: | cargo llvm-cov clean --workspace - cargo llvm-cov test --no-report --features=std,asn1der -- --test-threads=1 - cargo llvm-cov test --no-report --tests --features=std,asn1der -- compile_fail + cargo llvm-cov test --no-report --features=std -- --test-threads=1 + cargo llvm-cov test --no-report --tests --features=std -- compile_fail cargo llvm-cov report --lcov > lcov.txt env: RUSTFLAGS: --cfg __ui_tests