Skip to content

Commit

Permalink
Merge branch 'master' into cpu-fix-build
Browse files Browse the repository at this point in the history
  • Loading branch information
chifflier authored Aug 1, 2024
2 parents 4a24798 + f0a16c7 commit 7013d65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -43,7 +44,7 @@ num-bigint = { version = "0.4", optional = true }

[features]
default = ["std"]
bitvec = []
as_bitvec = ["bitvec"]
bigint = ["num-bigint"]
serialize = ["std", "cookie-factory"]
unstable = []
Expand Down
23 changes: 12 additions & 11 deletions src/ber/ber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Msb0, u8>, BerError> {
#[cfg(feature = "as_bitvec")]
pub fn as_bitslice(&self) -> Result<&BitSlice<u8, Msb0>, BerError> {
self.content.as_bitslice()
}

Expand Down Expand Up @@ -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<Msb0, u8>, BerError> {
self.as_slice()
.and_then(|s| BitSlice::<Msb0, _>::from_slice(s).map_err(|_| BerError::BerValueError))
#[cfg(feature = "as_bitvec")]
pub fn as_bitslice(&self) -> Result<&BitSlice<u8, Msb0>, BerError> {
self.as_slice().and_then(|s| {
BitSlice::<_, Msb0>::try_from_slice(s).map_err(|_| BerError::BerValueError)
})
}

pub fn as_sequence(&self) -> Result<&Vec<BerObject<'a>>, BerError> {
Expand Down Expand Up @@ -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<Msb0, u8>> {
BitSlice::<Msb0, _>::from_slice(self.data).ok()
#[cfg(feature = "as_bitvec")]
pub fn as_bitslice(&self) -> Option<&BitSlice<u8, Msb0>> {
BitSlice::<_, Msb0>::try_from_slice(self.data).ok()
}
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7013d65

Please sign in to comment.