From f0a16c7ad6d2c41505694b2ffd2843625d1f06ac Mon Sep 17 00:00:00 2001 From: Pierre Chifflier Date: Thu, 1 Aug 2024 16:44:41 +0200 Subject: [PATCH] Rename feature "bitvec" to "as_bitvec" and update to bitvec 1.0 (#73) --- Cargo.toml | 2 ++ src/ber/ber.rs | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7405bdb..f793353 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] asn1-rs = "0.6" +bitvec = { version="1.0", optional=true } cookie-factory = { version="0.3.0", optional=true } displaydoc = { version="0.2", default-features=false } nom = "7.0" @@ -43,6 +44,7 @@ num-bigint = { version = "0.4", optional = true } [features] default = ["std"] +as_bitvec = ["bitvec"] bigint = ["num-bigint"] serialize = ["std", "cookie-factory"] unstable = [] diff --git a/src/ber/ber.rs b/src/ber/ber.rs index bccbda4..509dc56 100644 --- a/src/ber/ber.rs +++ b/src/ber/ber.rs @@ -10,7 +10,7 @@ use alloc::boxed::Box; use alloc::vec::Vec; use asn1_rs::ASN1DateTime; use asn1_rs::Any; -#[cfg(feature = "bitvec")] +#[cfg(feature = "as_bitvec")] use bitvec::{order::Msb0, slice::BitSlice}; use core::convert::TryFrom; use core::ops::Index; @@ -268,8 +268,8 @@ impl<'a> BerObject<'a> { } /// Constructs a shared `&BitSlice` reference over the object data, if available as slice. - #[cfg(feature = "bitvec")] - pub fn as_bitslice(&self) -> Result<&BitSlice, BerError> { + #[cfg(feature = "as_bitvec")] + pub fn as_bitslice(&self) -> Result<&BitSlice, BerError> { self.content.as_bitslice() } @@ -564,10 +564,11 @@ impl<'a> BerObjectContent<'a> { } /// Constructs a shared `&BitSlice` reference over the object data, if available as slice. - #[cfg(feature = "bitvec")] - pub fn as_bitslice(&self) -> Result<&BitSlice, BerError> { - self.as_slice() - .and_then(|s| BitSlice::::from_slice(s).map_err(|_| BerError::BerValueError)) + #[cfg(feature = "as_bitvec")] + pub fn as_bitslice(&self) -> Result<&BitSlice, BerError> { + self.as_slice().and_then(|s| { + BitSlice::<_, Msb0>::try_from_slice(s).map_err(|_| BerError::BerValueError) + }) } pub fn as_sequence(&self) -> Result<&Vec>, BerError> { @@ -864,9 +865,9 @@ impl<'a> BitStringObject<'a> { } /// Constructs a shared `&BitSlice` reference over the object data. - #[cfg(feature = "bitvec")] - pub fn as_bitslice(&self) -> Option<&BitSlice> { - BitSlice::::from_slice(self.data).ok() + #[cfg(feature = "as_bitvec")] + pub fn as_bitslice(&self) -> Option<&BitSlice> { + BitSlice::<_, Msb0>::try_from_slice(self.data).ok() } } @@ -949,7 +950,7 @@ mod tests { assert!(obj.is_set(17)); } - #[cfg(feature = "bitvec")] + #[cfg(feature = "as_bitvec")] #[test] fn test_der_bitslice() { use std::string::String;